-->
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.  [ 4 posts ] 
Author Message
 Post subject: avoid extra select query on saving object with many-to-one
PostPosted: Fri Mar 30, 2007 12:36 pm 
Newbie

Joined: Thu Jan 04, 2007 12:27 am
Posts: 8
I have an object with a field mapped many-to-one e.g :

Code:
Course {
  User user ;
   ...
}

<class name="com.pkg.Course" table="COURSE" polymorphism="implicit">
   <id name="id" type="long" column="ID" unsaved-value="0">
           <generator class="identity"/>
   </id>
   
   <many-to-one name="user"
                     class="com.pkg.User"
                     column="USER_ID"
                     not-null="true"
                     cascade="none"/>
       ......
</class>


When I save a new object of course, session.save(Course), in the logs I see an extra select query on User, before every insert. I looked around in the forums but cant find a way to avoid it. Is there a way to avoid this query ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 30, 2007 4:32 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
What is the mapping of your User class?

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 30, 2007 8:03 pm 
Newbie

Joined: Thu Jan 04, 2007 12:27 am
Posts: 8
Does it depend on mapping of User class?

it looks like this
Code:
   <class name="com.pkg.User" table="USER">
      <id name="username" type="java.lang.String" column="ID">
         <generator class="assigned"/>
      </id>
              ....
      </class>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 02, 2007 12:30 pm 
Newbie

Joined: Thu Jan 04, 2007 12:27 am
Posts: 8
doesnt seem to work still.. anyone has a solution for this?


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