这几天踩的坑

   开源好处多多,降低了我们接触业内高端产品的门槛,一定程度上简化了开发的复杂度;但也带来了不少问题,使用开源就意味着要自己承担它的不稳定性带来的后果,回想这几天踩的坑,都是眼泪…还好不是我一人在用,还好可以多Google。

  列举几个把,以后坚决不犯:

   hibernate可以通过xml配置,自动由类生成表,可ssh结合以后,用原来的配置怎么也不行,原来是我在<prop key="hibernate.hbm2ddl.auto">create</prop>这句里没加hibernate所致,加上了之后update还是不可以自动建表,直至改成create,发现这个错误可真是花了不少时间,这应该是spring的bug吧

<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>

  在一些对数据库的操作中也才过不少的坑,列在下面,尤其是第三个,整整一晚上才整出来,以后坚决不犯

异常1:not-null property references a null or transient value
解决方法:将“一对多”关系中的“一”方,not-null设置为false


异常2:org.hibernate.TransientObjectException: object references an unsaved transient instance
解决方法:cascade="save-update,persist"

异常3:org.hibernate.QueryException: could not resolve property
解决方法:"from Category category where category.userID = :userID"修改为"from Category category whereuserID = :userID"或者"from Category category where category.user.id = :userID"


异常4:could not initialize proxy - the owning Session was closed
解决方法:设置lazyfalse

原文地址:https://www.cnblogs.com/90zyh/p/3117976.html