-->
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.  [ 2 posts ] 
Author Message
 Post subject: one-to-one-or-zero relationship causing many extra sql calls
PostPosted: Thu Aug 31, 2006 9:19 am 
Newbie

Joined: Wed Feb 15, 2006 11:52 am
Posts: 4
I am using 3.1.3, but I think this happens with 3.2 also.

I created a one-to-one-or-zero relationship something like this:

<many-to-one name="noteObject" entity-name="InformationalObject" column="parent_id" property-ref="parentId" insert="false" update="false" not-found="ignore" unique="true" lazy="false" fetch="join"/>

At first glance, it works fine in that it does join with the parent class, I get no errors, objects without notes have the field nulled and so on.

The problem is that after the initial select with the parent class, Hibernate is generating SQL statements for every null record. For example, if I am getting 100 parents and 75 have notes. Extra SQL statements are being generated looking for notes for the 25 parents that do not have them.

It appears that Hibernate thinks that these objects are not loaded rather than being null and keeps trying to load them.

In EntityType.java is test for a isNonExistant() method that was commented out. Is this some incomplete implementation that would fix this problem?

By the way, I also tried to get rid of the property-ref and use the parent_id as the primary key of the "note" table but it did not make a difference.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 13, 2006 7:02 am 
Newbie

Joined: Tue Sep 05, 2006 10:39 am
Posts: 13
I have the same problem. I am performance tuning my application and it is taking a big hit because of this.

My definition of the problem is this: I am fetching child objects which may or may not have a parent. The child's foreign key points to a non-primary key on the parent. This is not reflected by a foreign key constraint in the database (hence it allows child to have no parent).

If the child object has the foreign key 0 instead of null, which is the protocol in this database, then the parent which doesn't exist is not (& cannot) be instantiated, no problem, but then after processing the resultset, Hibernate fires off another query to fetch the parent that it could not find data for in the first query.

Obviously this is not an ideal mapping, since the database doesn't contain any relationships to enforce it, but this is obviously unexpected and inappropriate behaviour.

However this new app is a call-centre sitting on top of a very 'established' database, and I don't have the choice.

I have entered it in Jira as a minor bug.

http://opensource.atlassian.com/projects/hibernate/browse/HHH-2073

Feel free to vote for the bug. With a bit of luck it might not be such a big issue to change in the source - I haven't got as far as looking into Hib src changes yet.

Here's the mappings:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
  <class name="test.parent.basic.BasicParent"
    entity-name="test.parent.Parent" table="PARENT">
    <id name="id" column="PARENT_ID" access="field">
      <generator class="native" />
    </id>
    <property name="description" column="DESCRIPTION" not-null="true"
      access="field" />
    <property name="otherId" column="OTHER_ID" not-null="false" access="field"/>
  </class>
  <class name="test.child.basic.BasicChild"
    entity-name="test.child.Child" table="CHILD">
    <id name="id" column="CHILD_ID" access="field">
      <generator class="native" />
    </id>
    <property name="description" column="DESCRIPTION" not-null="true"
      access="field" />
    <many-to-one name="parent" property-ref="otherId" access="field"
      column="UNIQUE_PARENT" fetch="join" not-found="ignore" lazy="false"
      outer-join="true" />
  </class>
</hibernate-mapping>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.