[英]How to get only parent without children in Hibernate and without lazy exception?
How to get only parent without children in Hibernate and without lazy exception, when you trying to access chidlren filed after closing session? 当您尝试访问关闭会话后提交的儿童时,如何在Hibernate中仅获取没有孩子且没有懒惰异常的父项?
I mean, a kind of pure parent obtainingm but I beed to be sure, that somebody will not obtain them with getter or will not catch a lazy exception. 我的意思是,这是一种纯粹的父母获得,但我敢肯定,有人不会用吸气剂获得它们,也不会捕获懒惰的异常。
<class name="com.electronic.commerce.models.Category" table="Category">
<id name="id" type="long" access="property">
<column name="categoryId" length="20"/>
<generator class="native"/>
</id>
<property name="name" column="categoryName" type="string"/>
<property name="parentId" column="categoryParentId" type="long"/>
<bag name="children" table="Category" inverse="true" lazy="true" fetch="select">
<key>
<column name="categoryParentId" not-null="true"/>
</key>
<one-to-many class="com.electronic.commerce.models.Category"/>
</bag>
</class>
Mixed solution 混合溶液
Xml: Xml:
<prop key="hibernate.enable_lazy_load_no_trans">false</prop>
Java: Java:
DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition();
defaultTransactionDefinition.setPropagationBehavior(transactionDefinition);
transactionManager.getTransaction(defaultTransactionDefinition);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.