Hibernate version: 2.1.7
Mapping documents:
<hibernate-mapping package="myPackage.solicitation">
<class name="Solicitation" table="SOLICITATION" lazy="true">
<meta attribute="scope-field">protected</meta>
<meta attribute="implement-equals">true</meta>
<id name="id" column="SOLICITATION_ID" type="long" unsaved-value="0">
<meta attribute="scope-set">protected</meta>
<meta attribute="use-in-tostring">true</meta>
<generator class="sequence">
<param name="sequence">SOLICITATION_SEQ</param>
</generator>
</id>
<version name="version" column="VERSION" access="net.sf.hibernate.property.DirectPropertyAccessor">
<meta attribute="scope-field">protected</meta>
<meta attribute="scope-set">protected</meta>
<meta attribute="scope-get">protected</meta>
</version>
...
<set name="orders" lazy="true" inverse="true" where="MOD_FLAG != 2">
<meta attribute="scope-set">protected</meta>
<key column="SOLICITATION_ID" />
<one-to-many class="myPackage.Order" />
</set>
...
</class>
</hibernate-mapping>
<?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="myPackage.order">
<class name="Order" table="ORDERS">
<meta attribute="scope-field">protected</meta>
<meta attribute="implement-equals">true</meta>
<id name="id" column="ORDER_ID" type="long" unsaved-value="0">
<meta attribute="scope-set">protected</meta>
<meta attribute="use-in-tostring">true</meta>
<generator class="sequence">
<param name="sequence">ORDER_SEQ</param>
</generator>
</id>
<version name="version" column="VERSION" access="net.sf.hibernate.property.DirectPropertyAccessor">
<meta attribute="scope-field">protected</meta>
<meta attribute="scope-set">protected</meta>
<meta attribute="scope-get">protected</meta>
</version>
...
<many-to-one name="solicitation" column="SOLICITATION_ID" class="myPackage.Solicitation">
<meta attribute="use-in-tostring">true</meta>
</many-to-one>
...
</class>
</hibernate-mapping>
Code:
...
Solicitation solicitation = new SolicitationDAO().getById("1");
Order order = new Order();
order.setOrdered(new Date());
solicitation.addOrder(order);
BaseDAO.save(order);
...
public class Solicitation {
...
public void addOrder(Order order) {
this.orders.add(order);
order.setSolicitation(this);
}
...
}
Name and version of the database you are using: Oracle 8
The generated SQL (show_sql=true):
insert into ORDERS (VERSION, ADDRESS_TYPE_ID, ENCODING_ID, PURCHASE_ORDER_ID, SOLICITATION_ID, STATE_ID, ID_USERINFO, VIDEO_MEDIA_ID, COUNTRY_KEY, SOLICITOR_ID, ID_PREFIX, ODS_CUSTOMER_ID, TRACKING_NO, SECONDARY_STATE, SECONDARY_ERROR_TEXT, QUANTITY, UNIT_PRICE, UNIT_PRICE_CURRENCY, ADDRESSEE, ADDRESSEE_SUPPLEMENT, STREET, ZIP, CITY, COUNTY, ORDERED, SHIPPED, SHIPPING, COURIER, COMMENT_FIELD, COMMENT_PO, MOD_FLAG, MOD_STAMP, MOD_USER, ORDER_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
update SOLICITATION set VERSION=?, PRIORITY_ID=?, SOLICITOR_ID=?, NAME=?, CREATOR_ID=?, DEADLINE=?, COMMENT_FIELD=?, CREATED=?, EMAILED=?, MOD_FLAG=?, MOD_STAMP=?, MOD_USER=? where SOLICITATION_ID=? and VERSION=?
Hi,
I have trouble with a bidirectional 1-many relationship. Basically there is an update on the inverse many end which I would not expect to happen.
The many end is the class Solicitation (set as the inverse ending of the relationship), the one end is the class Order.
-I load a Solicitation object from the database
-I create a new Order object
-I add the order to the solicitation and set the solicitation on the order
-I save the order
-In the log file I can see the Insert-statement for the order but also an update for the solicitation - even though nothing changed here.
Why is this update on the solicitation executed? Anybody any idea? I appreciate it.
Thanks,
Ronald
|