hibernate 老说没有配方言
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
这句话明明就写在了配置文件里面,可老是没有写
错误如下:
Exception in thread "main" org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
name改成"hibernate.dialect"也不行
Hibernate-Version: 3.1.1
mysql -Verison: 4.0.16
用这种方法正确
static {
try {
configuration = new Configuration();
sessionFactory = configuration.configure().buildSessionFactory();
} catch (Throwable ex) {
throw new ExceptionInInitializerError(ex);
}
}
这种方式会出现异常
// static {
// try {
// // Create a configuration based on the properties file we've put
// Configuration config = new Configuration();
// config.addClass(Customer.class).addClass(Order.class);
// // Get the session factory we can use for persistence
// sessionFactory = config.buildSessionFactory();
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
第二种方式是针对使用properties文件配置hiernate的写法,使用hibernate.cfg.xml应使用第一种调用方式
或者在hibernate.cfg.xml中加入:
是由于没有配置:current_session_context_class
在hibernate的配置文件中增加<property name="current_session_context_class">thread</property>
原因:当你使用 Hibernate session factory的getCurrentSession() 函数时候,你可能见到过"No CurrentSessionContext configured!"
Unknown entity
找不到这个 entity 啊。
在你的 hibernate.cfg.xml 或 properties 文件里是否包含引用了MemberRegInfo.hbm.xml
?