简体   繁体   English

如何在Hibernate中让没有孩子且没有懒惰例外的唯一父母?

[英]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.

相关问题 如何在 Hibernate 中选择没有子对象的父对象? - How to select parent objects without children in Hibernate? 如何在没有Touch XML的情况下处理休眠中的惰性初始化异常 - How to handle Lazy Initialization Exception in hibernate without touch xml Hibernate - 如何只保留父母,让孩子保持原样 - Hibernate - How to persist only the parent, keeping the children as they are 没有惰性对象的休眠列表 - Hibernate List without Lazy Object 如何获取仅休眠状态下的实体的信息,例如使用Jersey进行延迟加载? - How to get info of only an entity in hibernate like lazy loading with Jersey? JPA休眠4延迟加载问题。 如何不急切地在ManyToOne中加载懒数据 - JPA hibernate 4 lazy load issue. How to load lazy data in ManyToOne without eager Hibernate - 如何在没有 N+1 的情况下获取另一个@OneToMany 惰性集合中的@OneToMany 惰性集合 - Hibernate - how to fetch @OneToMany lazy collection inside another @OneToMany lazy collection without N+1 Hibernate FetchType.LAZY 没有会话 - Hibernate FetchType.LAZY without session 没有惰性字段的休眠克隆实体 - Hibernate clone entity without lazy fields 如何在不下载孩子的情况下从 Firebase 获取儿童密钥? - How to get children keys from Firebase without downloading their children?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM