您的位置:首页 > 其它

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;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐