您的位置:首页 > 博客中心 > 数据库 >

hibernate配置之<property name="hbm2ddl.auto">create</property>导致每次创建SessionFactory都清空数据库中的数据

时间:2022-03-10 17:40

参考:http://stackoverflow.com/questions/6611437/how-to-make-hibernate-not-drop-tables

我遇到的问题就是:

List l = sess.createCriteria(News.class)
            .add( Restrictions.isNotEmpty("title"))
            .list();

抛出异常,Exception in thread "main" org.hibernate.MappingException: Property path [xxx.News.title] does not reference a collection

打开数据库查看表格,已经有的数据被清空了,select * from xxx_table 返回empty set,所以导致了这个异常

继续查看原因,是因为hibernate.cfg.xml中的<property name="hbm2ddl.auto">create</property>的问题,应该改成<property name="hbm2ddl.auto">update</property>

hibernate配置之<property name="hbm2ddl.auto">create</property>导致每次创建SessionFactory都清空数据库中的数据,布布扣,bubuko.com

热门排行

今日推荐

热门手游