日期:2014-05-17  浏览次数:20597 次

关于SessionFactory
public static void main(String args[]){

        SessionFactory sf = new Configuration()   
            .setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver")   
            .setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect")   
            .setProperty("hibernate.connection.url", "jdbc:mysql://localhost/huayi?useUnicode=true&characterEncoding=latin1")   
            .setProperty("hibernate.connection.username", "root")   
            .setProperty("hibernate.connection.password", "root")   
//           .setProperty("hibernate.hbm2ddl.auto", "create")   
//           validate               加载hibernate时,验证创建数据库表结构   
//           create                  每次加载hibernate,重新创建数据库表结构,这就是导致数据库表数据丢失的原因。   
//           create-drop        加载hibernate时创建,退出是删除表结构   
//           update                 加载hibernate自动更新数据库结构   
//             .addAnnotatedClass(Order.class)   
//             .addAnnotatedClass(Item.class)   
            .buildSessionFactory();   
           
        Session session = sf.openSession();   
        session.beginTransaction();   
        List result = session.createQuery("from PlcAmsNetID").list();   

           session.getTransaction().commit();   
                    System.out.println("done...");   
    }    


提示
Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: PlcAmsNetID is not mapped [from PlcAmsNetID]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:158)
at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:87)
at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:2