-->
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: when saving several selects execute b4 inserting
PostPosted: Sat Dec 27, 2008 3:48 pm 
Newbie

Joined: Mon Dec 15, 2008 1:32 am
Posts: 3
[Running Hibernate 3.3.1]
I have a little bit of a challenge. I have got a situation where when I try to do an insert in a table by saving an object i get like 3 select statement executed be4 the actual insert takes place. My object structure is simple. An Item property contains category property which is an Entity. My mapping:




Code:
<hibernate-mapping package="com.pmega.easybuy.domain" >
   <class name="ItemPost" table="item_posts">
      <cache  usage="read-write" />
      <id name="postId" type="string" column="post_id" length="15">
         <generator class="assigned"  />
      </id>
      <property name="itemPostEnabled" type="boolean"
         column="post_enabled" not-null="true" />

      <property name="reactivateCount" type="integer"
         column="reactivate_count" />

      <property name="datePosted" type="calendar">
         <column name="date_posted" not-null="true" />
      </property>
      <property name="expiryDate" type="calendar" >
         <column name="date_expired" not-null="true" />
      </property>

      <property name="posterUsername" type="string"  column="username" not-null="true" />
      
      <many-to-one name="item" column="item_id" unique="true" cascade="delete"
       not-null="true"    class="Item" update="false" >               
      </many-to-one>
         
      <set name="comments" table="post_comments" cascade="delete">
         <cache usage="read-write"/>
         <key column="post_id" />
         <many-to-many column="comment_id" unique="true"
            class="Comment" />
      </set>
   </class>
</hibernate-mapping>


The above is for my Item class

Code:
<hibernate-mapping package="com.pmega.easybuy.domain">
   <class name="Category" table="categories"    dynamic-update="true" >         
      <cache  usage="read-only"  />
      <id name="categoryId" type="long" column="category_id">
         <generator class="identity" />
      </id>
      <property name="description" type="string" column="description" />
      <property name="name" type="string" column="name"
      not-null="true" unique="true" />
   </class>
</hibernate-mapping>


The above is for my Category class

My DAO looks like :
Code:
@Transactional(readOnly = false)
   public ItemPost save(ItemPost itemPost) {
      Session session = getSession();
      Transaction tx = null;
      try {
         tx = session.beginTransaction();
         session.save(itemPost.getItem());
         session.save(itemPost);
         tx.commit();
      } catch (Exception e) {
         // TODO: handle exception
         tx.rollback();
         e.printStackTrace();
      }

      return itemPost;
   }


Actually, for the DAO, I have an ItemPost which has been initialized with an Item Object, and d Item obj has been initialized with a Category obj with id of a persisted Category. i.e The Category obj only has categoryId property set, other properties arent set.

Challenge:
What i notice is dat wen i try saving: i see at least three select category statements
Code:
Hibernate: select category0_.category_id as category1_6_, category0_.description as descript2_6_, category0_.name as name6_ from categories category0_
Hibernate: select category0_.category_id as category1_6_, category0_.description as descript2_6_, category0_.name as name6_ from categories category0_
Hibernate: select category0_.category_id as category1_6_, category0_.description as descript2_6_, category0_.name as name6_ from categories category0_


before the Item object is eventually inserted into the DB, and becomes visible. I feel this select statements would cause sm kind of performance drawback for a production app.
I sincerely hope smone with a cue responds to this, cos my last two posts havent still gotten any reply. I hope i av bin xpilicit enof. Further info about d app wld b provided


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.