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
|