Hibernate不能自动建表问题解决

来源:互联网 发布:软件杂志高岚 编辑:程序博客网 时间:2024/05/16 01:48

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


0 0
原创粉丝点击