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

参考: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>

原文地址:https://www.cnblogs.com/qrlozte/p/3795860.html