`
mengz
  • 浏览: 78503 次
社区版块
存档分类
最新评论

另类原因造成的LazyInitializationException

阅读更多

这两天在玩EntityManager,取出Hibernate的Criteria在系统里做list().在加入OpenEntityManagerInViewFilter的情况下还是出现LazyInitializationException。

后查出原因是BaseEntity中的equals(), toString()和hashCode()方法都是用commons-lang的Builder工具构造的。

删掉hashCode()中的HashCodeBuilder.reflectionHashCode(this);问题解决。

 

分享到:
评论
2 楼 kevinhrw 2009-02-15  
不要统计Collection类型的字段的hashCode就可以解決問題:org.hibernate.LazyInitializationException: illegal access to loading collection,不錯,哈哈.學習了~
1 楼 kevinhrw 2009-02-15  
public int hashCode() {
		return new HashCodeBuilder(818340233, -1334823845).append(this.supplyOriginal).append(this.cargoWarehouse).append(this.cargoUnit).append(
				this.userId).append(this.comment).append(this.supply).append(this.inDate).append(this.cargoBuyId).append(this.supplyFactory).append(
				this.totalMoney).append(this.buySerial).append(this.price).append(this.cargoFetchs).append(this.cargoTypeId).append(this.cargo)
				.append(this.quantity).toHashCode();
	}


我的方法如上,沒有你的那句也出現這個問題哦~

相关推荐

Global site tag (gtag.js) - Google Analytics