Hibernate version: 3.2
Mapping documents:
Code:
<class name="ManagedObject" table="managed_object" proxy="ManagedObject">
<id name="name" type="string" unsaved-value="null">
<column name="name" length="50"/>
<generator class="assigned"/>
</id>
<version name="version" column="version" access="field"/>
<property name="description" column="description" type="text"/>
<set name="policies" table="managed_object_policies" lazy="true">
<key column="managed_object_id" not-null="true"
foreign-key="mobj_policies_mobj_fk"/>
<many-to-many class="Policy" column="policy_id"
foreign-key="mobj_policies_policy_fk"></many-to-many>
</set>
</class>
Code:
<class name="Policy" table="policy" proxy="Policy" >
<id name="name" type="string" access="field" unsaved-value="null">
<column name="name" length="50"/>
<generator class="assigned"/>
</id>
<version name="version" column="version" access="field"/>
<property name="description" column="description" type="text"/>
<set name="acceptableAttributes" table="policy_attributes" lazy="true">
<key column="policy_id" not-null="true"
foreign-key="policy_attributes_policy_fk"/>
<many-to-many class="PolicySimpleValue" column="policy_simple_value_id"
foreign-key="policy_attributes_value_fk"/>
</set>
</class>
Code:
<class name="PolicySimpleValue" table="policy_simple_value" proxy="PolicySimpleValue">
<id name="name" type="string" access="field" unsaved-value="null" >
<column name="name" length="50"/>
<generator class="assigned"/>
</id>
<version name="version" column="version" access="field"/>
<property name="description" column="description" type="text"/>
<property name="type" column="value_type" type="string" length="10" access="field"/>
<set name="policies" inverse="true" table="policy_attributes" lazy="true">
<key column="policy_simple_value_id" />
<many-to-many column="policy_id" class="Policy" />
</set>
</class>
b]Code between sessionFactory.openSession() and session.close():[/b]
Code:
// The _* attribues are hash-maps where objects are cached.
session.beginTransaction();
ManagedObject mobj=(ManagedObject)sess
.get(ManagedObject.class, pMobjName);
Set<Policy> pls=mobj.getPolicies();
if ( pls != null )
for ( Policy pol : pls) {
_policies.put(pol.getName(), pol);
if ( pol.getAcceptableAttributes() != null ) {
for ( PolicySimpleValue ps : pol.getAcceptableAttributes() ) {
_values.put(ps.getName(), ps);
}
}
}
_managedObjects.put(mobj.getName(), mobj);
session.getTransaction().commit();
Name and version of the database you are using: Postgres 8.2The generated SQL (show_sql=true):Code:
For each policy and its acceptable atributes all these sqls
are called when commit is called.
Hibernate:
update
auth.policy
set
version=?,
description=?
where
name=?
and version=?
Hibernate:
delete
from
auth.policy_attributes
where
policy_id=?
Hibernate:
insert
into
auth.policy_attributes
(policy_id, policy_simple_value_id)
values
(?, ?)
The problem
As you see no modification has been made to any of the objects
involved in the java-code, but when commit() is called a lot of
inserts/updates/deletes are done.
I'm not sure if this is related to my id's bean "assigned", but as I understand
from hibernate docs all the steps have been done for an assigned id to work properly, except for implementing
Interceptor.isUnsaved(), this method is not part of Interceptor and really could not find how to implement/use a similar method.
Any ideas how to correct this problem, or how to avoid it ?
Thanks very much in advance
tonio