-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate update commands results in just a query
PostPosted: Fri Nov 03, 2006 8:50 pm 
Newbie

Joined: Sun Oct 15, 2006 1:52 am
Posts: 5
I have the following code which just query an object from the database.
But when I turn on hibernate sql output. it causes 2 sqls:
1. query
2. update .

My question is why hibernate generate the 2nd update? I did not modify the cat object at all in my transaction?

Code:
private static Cat getCat(String name, Home home) {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();

      session.beginTransaction();
               
                // cause hibernate to create 1 query. This is expected
      Query query = session
            .createQuery(
                  "from Cat as cat where  cat.name= :name and cat.home.id = :homeid");
      
      List result = query.setString("name", name).setLong("homeid",
                  home.getId().longValue()).list();
               
                // why hibernate caused a sql update query here?
      session.getTransaction().commit();

      if (result.size() == 1) {
         return (Cat) result.get(0);
                }
}



Here is my mapping file:
[code ]


<class name="com.testproject.model.Cat" table="BUILDS"
lazy="true">
<id name="id" column="CAT_ID">
<generator class="native" />
</id>
<version name="version" column="version"
type="java.lang.Integer" />


<property name="name" not-null="true" />

<many-to-one name="home" column="HOME_ID"
class="com.testproject.model.Home" not-null="true" />


</class>

[/code]


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

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.