Hibernate不能自动建表问题解决
2014-08-26 12:52
323 查看
hibernate.cfg.xml中dialect 配置方言为org.hibernate.dialect.MySQLInnoDBDialect是不能自动建表,改为org.hibernate.dialect.MySQLDialect或org.hibernate.dialect.MySQL5Dialect
另外hbm2ddl.auto设置为update即可
另附SessionFactoryFactory
public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory();
public static SessionFactory buildSessionFactory(){
try{
// Create the SessionFactory from hibernate.cfg.xml
Configuration cfg = new Configuration().configure();
SessionFactory sf = cfg.buildSessionFactory(new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).build());
return sf;
}catch (Throwable ex){
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation filaed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory(){
return sessionFactory;
}
}
另外hbm2ddl.auto设置为update即可
另附SessionFactoryFactory
public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory();
public static SessionFactory buildSessionFactory(){
try{
// Create the SessionFactory from hibernate.cfg.xml
Configuration cfg = new Configuration().configure();
SessionFactory sf = cfg.buildSessionFactory(new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).build());
return sf;
}catch (Throwable ex){
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation filaed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory(){
return sessionFactory;
}
}
相关文章推荐
- 解决Hibernate不能自动创建数据库表的问题
- 解决Mysql连接池被关闭 ,hibernate尝试连接不能连接的问题。 (默认mysql连接池可以访问的时间为8小时,如果超过8小时没有连接,mysql会自动关闭连接池。
- 解决Mysql连接池被关闭 ,hibernate尝试连接不能连接的问题。 (默认mysql连接池可以访问的时间为8小时,如果超过8小时没有连接,mysql会自动关闭连接池。系统发布第二天访问链接关闭问题。
- vc++6.0中如何解决不能自动列出成员的问题
- 【转】解决长串英文字母显示不能自动换行的问题和td中汉字自动换行 && CSS强制不换行
- 解决PHPcms 2008 sp4 注册选择模型关闭后,注册不能自动登录的问题
- 采用C3P0连接池解决spring+hibernate+mysql 访问空闲8小时后自动断开连接的问题
- 解决IE7不能自动完成表单的问题
- 作业自动在每天的凌晨2点执行和解决作业不能执行的问题
- Hibernate3自动建表总有一张建立不成功问题及其解决!
- 如何解决eWebEditor在线编辑器的远程自动上传功能不能使用的问题?
- 在Eclipse3.4中安装Ext和删除Spket以及不能自动提示问题的解决总结
- 如何解决eWebEditor在线编辑器的远程自动上传功能不能使用的问题?
- ASP.NET中应用UltraWebGrid控件时在Cell中按一下回车后不能自动转到下一单元格的问题及解决办法
- 解决长串英文字母显示不能自动换行的问题(转)
- 解决Debian中ibus输入法不能自动启动的问题
- 解决 IE Firefox下 字符串不能自动换行(折行)问题
- windows防火墙不能自动运行的问题解决一例
- MySQL+Hibernate下连接空闲8小时自动断开问题解决方案
- HibernateDaoSupport getSession()不能释放资源的问题及解决方法