Unknown entity: Students解決方法
【hibernate 5以上的版本不再需要 ServiceRegistry 來創建 sessionFactory
所以初始方法的代碼可以改成
Configuration config = new Configuration().configure();
sessionFactory = config.buildSessionFactory();
session = sessionFactory.openSession();
transaction = session.beginTransaction();】
復制以上網友的評論表示感謝!
【hibernate 5以上的版本不再需要 ServiceRegistry 來創建 sessionFactory
所以初始方法的代碼可以改成
Configuration config = new Configuration().configure();
sessionFactory = config.buildSessionFactory();
session = sessionFactory.openSession();
transaction = session.beginTransaction();】
復制以上網友的評論表示感謝!
2016-10-23
public static Session getSession() {
//加載配置文件
1 Configuration configuration = new Configuration().configure("hibernate.cfg.xml");
//創建會話工廠
SessionFactory factory = configuration.buildSessionFactory();
//創建會話
Session session = factory.openSession();
return session;
}
//加載配置文件
1 Configuration configuration = new Configuration().configure("hibernate.cfg.xml");
//創建會話工廠
SessionFactory factory = configuration.buildSessionFactory();
//創建會話
Session session = factory.openSession();
return session;
}
2016-10-21
</property>
<mapping resource="Students.hbm.xml"/>
<mapping resource="Students.hbm.xml"/>
2016-10-20
<property name="connection.password"></property>
<!-- 顯示SQL語句 -->
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<!-- 定義方言 -->
<property name="dialect">
org.hibernate.dialect.MySQLDialect
<!-- 顯示SQL語句 -->
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<!-- 定義方言 -->
<property name="dialect">
org.hibernate.dialect.MySQLDialect
2016-10-20
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/hibernate?useUnicode=true&amp;characterEncoding=utf8
</property>
<property name="connection.username">root</property>
com.mysql.jdbc.Driver
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/hibernate?useUnicode=true&amp;characterEncoding=utf8
</property>
<property name="connection.username">root</property>
2016-10-20