-->
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.  [ 3 posts ] 
Author Message
 Post subject: Custom user type causes update and VERY slow query
PostPosted: Fri Jul 23, 2004 2:00 pm 
Newbie

Joined: Wed Feb 04, 2004 10:31 pm
Posts: 10
I have a system where a number of entities represent the ids os objects which never change and may be cached in an application (imagine state abbreviations or a product catalog).
When I declare these references as many-to-one associations hibernate does a join which is slow. Instead I developed a UserType which converts an id to an object held in application cache.
My declaration looks like this
<class name="com.babel17.fbdraft.impl.hibernate.PlayerImplLite" table="player" polymorphism="explicit">
<id name="playerId" type="long" unsaved-value="null">
<column name="player_id" sql-type="int8" not-null="true"/>
<generator class="increment"/>
</id>
<property name="firstName" column="first_name" type="string" not-null="true" length="40"/>
...
<property name="team" type="com.babel17.fbdraft.hibernate.MLBTeamUserType">
<column name="team_id"/>>
</property>
</class>

The generated SQL is
Hibernate: select this.player_id as player_id0_, this.first_name as first_name0_, this.last_name as last_name0_, this.team_id as team_id0_ from player this where 1=1
Hibernate: update player set first_name=?, last_name=?, team_id=? where player_id=?
The query takes 45 sec to retrieve 800 players
If I comment out the team property or declare mutable=false then the update is not issued and the query takes less than 1 sec
So what is going on? Why is an update issued and how do I cause it to go away without making the object immutable


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 23, 2004 3:08 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Fix your implementation of UserType.equals(x, y)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 23, 2004 4:17 pm 
Newbie

Joined: Wed Feb 04, 2004 10:31 pm
Posts: 10
1) Good call the equals function was broken
2) However fixing equals does not alter the behavior described in my first post - I checked and equals always returns true when called.
It is true that DeepCopy simply returns the passes argument - I presume this is OK for a passed immutable instance.
The code still does the right thing when the object is marked in the hbm file with mutable="false" but I still don't understant what hibernate is trying to do or why not why it takes so long


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