-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 
Author Message
 Post subject: Lazy ignored for Hibernate+H2, but ok for Hibernate+MySQL
PostPosted: Thu Mar 03, 2016 5:03 pm 
Newbie

Joined: Sun Feb 28, 2016 3:16 pm
Posts: 17
H2 1.4.191.
MySQL 5.7.11.
Hibernate: 5.1.0.Final.
All Spring modules: 4.2.5.RELEASE.

How I can fix this?
Next code gives me result with children:

Code:
getSessionFactory().getCurrentSession().createQuery(
            "from Category where categoryParentId = :parentId").setLong("parentId", parentId).list();

//------------------------------------------------
Code:
<class name="com.domain.Category" table="Category">
    <id name="id" type="long" access="property">
        <column name="categoryId" length="20"/>
        <generator class="identity"/>
    </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.domain.models.Category"/>
    </bag>
</class>

//----------------------------...
Code:
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
            <prop key="hibernate.enable_lazy_load_no_trans">true</prop>
            <prop key="hibernate.show_sql">false</prop>
        </props>
    </property>


Last edited by ArthurDn on Fri Mar 04, 2016 4:58 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Lazy ignored for Hibernate+H2, but ok for Hibernate+MySQL
PostPosted: Fri Mar 04, 2016 1:24 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
I don't think this query works because "categoryParentId" is an SQL column and not an entity property.
You should change it to:

getSessionFactory().getCurrentSession().createQuery(
"select c from Category c where c.parentId= :parentId")
.setLong("parentId", parentId)
.list();


Top
 Profile  
 
 Post subject: Re: Lazy ignored for Hibernate+H2, but ok for Hibernate+MySQL
PostPosted: Fri Mar 04, 2016 4:57 am 
Newbie

Joined: Sun Feb 28, 2016 3:16 pm
Posts: 17
Interesting, my query works and your query works too, but lazy is ignored for both cases.
Checked.


Top
 Profile  
 
 Post subject: Re: Lazy ignored for Hibernate+H2, but ok for Hibernate+MySQL
PostPosted: Fri Mar 04, 2016 6:11 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
I've never seen this issue.

Can you provide a replicating test case and assign it to a JIRA issue or as a Pull Request on hibernate-orm?

You can use our test case templates.


Top
 Profile  
 
 Post subject: Re: Lazy ignored for Hibernate+H2, but ok for Hibernate+MySQL
PostPosted: Fri Mar 04, 2016 8:03 am 
Newbie

Joined: Sun Feb 28, 2016 3:16 pm
Posts: 17
I've created an issue:
https://hibernate.atlassian.net/browse/HHH-10586
But I did not understood, into what repository should I do a pool request (URL)?


Top
 Profile  
 
 Post subject: Re: Lazy ignored for Hibernate+H2, but ok for Hibernate+MySQL
PostPosted: Fri Mar 04, 2016 10:50 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You need to provide a replicating test case. You need to download the test case templates, write a test case that fails and attach it to this JIRA issue that you created.


Top
 Profile  
 
 Post subject: Re: Lazy ignored for Hibernate+H2, but ok for Hibernate+MySQL
PostPosted: Fri Mar 04, 2016 12:12 pm 
Newbie

Joined: Sun Feb 28, 2016 3:16 pm
Posts: 17
I've attached whole small project and specified failed test.
Sorry, I saw template, but did not get, what exactly I need to do.


Top
 Profile  
 
 Post subject: Re: Lazy ignored for Hibernate+H2, but ok for Hibernate+MySQL
PostPosted: Fri Mar 04, 2016 4:09 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You have DBUnit config issues:

Code:
<dataset>
    <Category categoryId="1"
              categoryName="NAME"
              categoryImage="IMAGE"
              categoryParentId="0"/>
    <Category categoryId="2"
              categoryName="NAME"
              categoryImage="IMAGE"
              categoryParentId="1"/>
</dataset>


There is no categoryParentId="0" because there is no such Category with an id of 0.

You have to supply a test case with no dependency on Spring or DBUnit using the test case templates. You need to read that blog post. There's also a link to templates that use native Hibernate API.

Also, the tests don't start because of failing H2 config. I had to change the URL to:

Code:
url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=10000


Top
 Profile  
 
 Post subject: Re: Lazy ignored for Hibernate+H2, but ok for Hibernate+MySQL
PostPosted: Fri Mar 04, 2016 6:09 pm 
Newbie

Joined: Sun Feb 28, 2016 3:16 pm
Posts: 17
Thank you very much, fixed other bugs.
Now I have org.springframework.orm.hibernate5.HibernateOptimisticLockingFailureException
But that is another case.
Have a good day!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.