-->
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: Strange behavior inserting an class with a composite-element
PostPosted: Thu Mar 04, 2004 4:21 pm 
Newbie

Joined: Thu Mar 04, 2004 4:00 pm
Posts: 2
hibernate version: 2
mapping doc:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="entities">
   <class
      name="Order"
      table="[Order]"
      dynamic-update="true"
      dynamic-insert="true"
      >

      <id name="orderId" column="orderId">
         <generator class="identity"/>
      </id>

      <property
         name="orderDate"
         not-null="true"
         length="4"
         type="timestamp"
         unique="false"
         />

      <set
         name="orderItems"
         table="OrderItem"
         lazy="true"
         cascade="all"
         >

         <key column="OrderId"/>

         <composite-element class="OrderItem">
            <property name="amount"/>
            <property name="price"/>
            <many-to-one name="product" column="productId"/>
         </composite-element>

      </set>

   </class>
</hibernate-mapping>

database: MSSQL2000 using jdbc driver from microsoft
tables: order, orderItem and product
relations: order can have one-to-many orderItems
product can be part of one-to-many orderItems

problem:

It is not really a problem, it just a concern...

It all happens when I was inserting an Order with various OrderItems, the Order was inserted along with all its OrderItems but a strange SQL DELETE statement was excecuted during the operation

Hibernate: insert into [Order] (orderDate) values (?) select SCOPE_IDENTITY()
Hibernate: insert into OrderItem (OrderId, amount, price, productId) values (?, ?, ?, ?)
Hibernate: delete from OrderItem where OrderId=? and amount=? and price=? and productId=?
Hibernate: insert into OrderItem (OrderId, amount, price, productId) values (?, ?, ?, ?)

Is this a normal behavior of hibernate? why it tries to delete from the join table?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 04, 2004 4:40 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
No, this is not normal. May be the result of a broken equals/hashCode. Use the Hibernate log to find the cause.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 04, 2004 4:46 pm 
Newbie

Joined: Thu Mar 04, 2004 4:00 pm
Posts: 2
That was it!!...Problem solved...

thank you


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.