waited for couple of days to get reply from hibernate gurus, but fruitless. So, though a small test case will help in getting your attention.
It would be great if anyone can throw some light on the issue.
Mapping Files
Quote:
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="false"
package="com.test.services.person">
<!-- This is the Hibernate mapping file for Rate Plans. -->
<class name="Person" table="PERSON">
<cache usage="transactional" />
<id name="uuid"
type="com.test.services.util.hibernate.UUIDVarcharType"
column="PERSON_UUID">
<generator class="assigned" />
</id>
<property name="firstName" column="FIRST_NAME" not-null="true" />
<set name="cats" inverse="true" cascade="all">
<cache usage="transactional" />
<key column="CAT_UUID" />
<one-to-many class="Cat" />
</set>
</class>
</hibernate-mapping>
Quote:
<?xml version="1.0"?>
<!-- $Id: Phone.hbm.xml,v 1.5 2005/09/06 19:21:07 amills Exp $ -->
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="false" package="com.test.services.person">
<!-- This is the Hibernate mapping file for Phone. -->
<class name="Cat" table="CAT">
<cache usage="transactional"/>
<id name="catUUID" type="com.test.services.util.hibernate.UUIDVarcharType"
column="CAT_UUID">
<generator class="assigned"/>
</id>
<property name="catName" column="CAT_NAME"/>
<many-to-one name="person" class="Person" column="PERSON_UUID" not-null="true"/>
</class>
</hibernate-mapping>
Code:
/*
* Copyright 2003 Test, Inc. All rights reserved.
* TEST PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
package com.test.services.person;
import java.io.Serializable;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.logging.Logger;
import com.test.util.UUID;
/**
* @author Catherine Curtiss
*/
public class Person implements Serializable{
static final long serialVersionUID = -37888934769379600L;
Logger logger = Logger.getLogger(Person.class.getName());
protected UUID uuid;
protected String firstName;
protected SortedSet cats; //list of phone objects
/**
* @param uuid
*/
public Person() {
this.uuid = new UUID();
cats=new TreeSet();
}
/**
* @return Returns the cats.
*/
public SortedSet getCats() {
if (cats == null) {
cats = new TreeSet();
}
return cats;
}
/**
* @param cats The cats to set.
*/
public void setCats(Set cats) {
if(cats instanceof SortedSet) {
this.cats = (SortedSet) cats;
}
else {
TreeSet ts = new TreeSet(cats);
this.cats = ts;
}
}
/**
* @return Returns the firstName.
*/
public String getFirstName() {
return firstName;
}
/**
* @param firstName The firstName to set.
*/
public void setFirstName(String firstName) {
this.firstName = firstName;
}
/**
* @return Returns the uuid.
*/
public UUID getUuid() {
return uuid;
}
/**
* @param uuid The uuid to set.
*/
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
public void addCat(Cat cat) {
if(cats == null) {
cats = new TreeSet();
}
cats.add(cat);
cat.setPerson(this);
}
}
Code:
/*
* Copyright 2003 Test, Inc. All rights reserved.
* TEST PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
package com.test.services.person;
import java.io.Serializable;
import java.util.logging.Logger;
import com.test.util.UUID;
/**
* @author Catherine Curtiss
*/
public class Cat implements Serializable {
static final long serialVersionUID = 5611388090864904258L;
protected UUID catUUID;
protected String catName;
protected Person person;
//Initialize the logger
protected static Logger logger =
Logger.getLogger(Cat.class.getName());
public Cat() {
catUUID = new UUID();
}
/**
* @return Returns the catName.
*/
public String getCatName() {
return catName;
}
/**
* @param catName The catName to set.
*/
public void setCatName(String catName) {
this.catName = catName;
}
/**
* @return Returns the catUUID.
*/
public UUID getCatUUID() {
return catUUID;
}
/**
* @param catUUID The catUUID to set.
*/
public void setCatUUID(UUID catUUID) {
this.catUUID = catUUID;
}
/**
* @return Returns the person.
*/
public Person getPerson() {
return person;
}
/**
* @param person The person to set.
*/
public void setPerson(Person person) {
this.person = person;
}
}
Code which creates and loads these objects.
Code:
Person p=new Person();
Cat c=new Cat();
p.setFirstName("test person");
c.setCatName("test cat");
p.addCat(c);
Session s=HibernateUtil.currentSession();
org.hibernate.Transaction tx=s.beginTransaction();
s.save(p);
tx.commit();
HibernateUtil.closeSession();
for(int i=0;i<10;i++){
Session s1=HibernateUtil.currentSession();
org.hibernate.Transaction tx1=s1.beginTransaction();
Person p1=(Person)s1.get(Person.class,p.getUuid());
tx1.commit();
HibernateUtil.closeSession();
}
Session s2=HibernateUtil.currentSession();
org.hibernate.Transaction tx2=s2.beginTransaction();
s2.delete(p);
tx2.commit();
HibernateUtil.closeSession();
Code:
[11-07-05 19:25:14](F)<205>[TransactionalCache ]{10} cache lookup: com.test.services.person.Cat#FE2093DF686743F8B5DD9A355B4406D1
[11-07-05 19:25:14](F)<206>[TransactionalCache ]{10} cache miss
Hibernate: select cat_.CAT_UUID, cat_.CAT_NAME as CAT2_9_, cat_.PERSON_UUID as PERSON3_9_ from CAT cat_ where cat_.CAT_UUID=?
Hibernate: insert into PERSON (FIRST_NAME, PERSON_UUID) values (?, ?)
Hibernate: insert into CAT (CAT_NAME, PERSON_UUID, CAT_UUID) values (?, ?, ?)
[11-07-05 19:25:14](F)<207>[TransactionalCache ]{10} inserting: com.test.services.person.Person#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:14](F)<208>[TransactionalCache ]{10} inserting: com.test.services.person.Cat#FE2093DF686743F8B5DD9A355B4406D1
[11-07-05 19:25:14](F)<209>[TransactionalCache ]{10} cache lookup: com.test.services.person.Person#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:14](F)<210>[TransactionalCache ]{10} cache hit
Hibernate: select cats0_.CAT_UUID as CAT1_2_, cats0_.CAT_UUID as CAT1_1_, cats0_.CAT_NAME as CAT2_9_1_, cats0_.PERSON_UUID as PERSON3_9_1_, person1_.PERSON_UUID as PERSON1_0_, person1_.FIRST_NAME as FIRST2_46_0_ from CAT cats0_ inner join PERSON person1_ on cats0_.PERSON_UUID=person1_.PERSON_UUID where cats0_.CAT_UUID=?
[11-07-05 19:25:14](F)<211>[TransactionalCache ]{10} cache lookup: com.test.services.person.Person.cats#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:14](F)<212>[TransactionalCache ]{10} cache miss
[11-07-05 19:25:14](F)<213>[TransactionalCache ]{10} caching: com.test.services.person.Person.cats#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:14](F)<214>[TransactionalCache ]{10} cache lookup: com.test.services.person.Person#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:14](F)<215>[TransactionalCache ]{10} cache hit
[11-07-05 19:25:14](F)<216>[TransactionalCache ]{10} cache lookup: com.test.services.person.Person.cats#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:14](F)<217>[TransactionalCache ]{10} cache miss
Hibernate: select cats0_.CAT_UUID as CAT1_2_, cats0_.CAT_UUID as CAT1_1_, cats0_.CAT_NAME as CAT2_9_1_, cats0_.PERSON_UUID as PERSON3_9_1_, person1_.PERSON_UUID as PERSON1_0_, person1_.FIRST_NAME as FIRST2_46_0_ from CAT cats0_ inner join PERSON person1_ on cats0_.PERSON_UUID=person1_.PERSON_UUID where cats0_.CAT_UUID=?
[11-07-05 19:25:14](F)<218>[TransactionalCache ]{10} caching: com.test.services.person.Person.cats#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:14](F)<219>[TransactionalCache ]{10} cache lookup: com.test.services.person.Person#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:14](F)<220>[TransactionalCache ]{10} cache hit
[11-07-05 19:25:14](F)<221>[TransactionalCache ]{10} cache lookup: com.test.services.person.Person.cats#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:14](F)<222>[TransactionalCache ]{10} cache miss
Hibernate: select cats0_.CAT_UUID as CAT1_2_, cats0_.CAT_UUID as CAT1_1_, cats0_.CAT_NAME as CAT2_9_1_, cats0_.PERSON_UUID as PERSON3_9_1_, person1_.PERSON_UUID as PERSON1_0_, person1_.FIRST_NAME as FIRST2_46_0_ from CAT cats0_ inner join PERSON person1_ on cats0_.PERSON_UUID=person1_.PERSON_UUID where cats0_.CAT_UUID=?
[11-07-05 19:25:14](F)<223>[TransactionalCache ]{10} caching: com.test.services.person.Person.cats#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:14](F)<224>[TransactionalCache ]{10} cache lookup: com.test.services.person.Person#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:14](F)<225>[TransactionalCache ]{10} cache hit
[11-07-05 19:25:14](F)<226>[TransactionalCache ]{10} cache lookup: com.test.services.person.Person.cats#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:14](F)<227>[TransactionalCache ]{10} cache miss
Hibernate: select cats0_.CAT_UUID as CAT1_2_, cats0_.CAT_UUID as CAT1_1_, cats0_.CAT_NAME as CAT2_9_1_, cats0_.PERSON_UUID as PERSON3_9_1_, person1_.PERSON_UUID as PERSON1_0_, person1_.FIRST_NAME as FIRST2_46_0_ from CAT cats0_ inner join PERSON person1_ on cats0_.PERSON_UUID=person1_.PERSON_UUID where cats0_.CAT_UUID=?
[11-07-05 19:25:14](F)<228>[TransactionalCache ]{10} caching: com.test.services.person.Person.cats#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:14](F)<229>[TransactionalCache ]{10} cache lookup: com.test.services.person.Person#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:14](F)<230>[TransactionalCache ]{10} cache hit
[11-07-05 19:25:14](F)<231>[TransactionalCache ]{10} cache lookup: com.test.services.person.Person.cats#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:14](F)<232>[TransactionalCache ]{10} cache miss
Hibernate: select cats0_.CAT_UUID as CAT1_2_, cats0_.CAT_UUID as CAT1_1_, cats0_.CAT_NAME as CAT2_9_1_, cats0_.PERSON_UUID as PERSON3_9_1_, person1_.PERSON_UUID as PERSON1_0_, person1_.FIRST_NAME as FIRST2_46_0_ from CAT cats0_ inner join PERSON person1_ on cats0_.PERSON_UUID=person1_.PERSON_UUID where cats0_.CAT_UUID=?
[11-07-05 19:25:14](F)<233>[TransactionalCache ]{10} caching: com.test.services.person.Person.cats#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:14](F)<234>[TransactionalCache ]{10} cache lookup: com.test.services.person.Person#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:14](F)<235>[TransactionalCache ]{10} cache hit
[11-07-05 19:25:14](F)<236>[TransactionalCache ]{10} cache lookup: com.test.services.person.Person.cats#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:14](F)<237>[TransactionalCache ]{10} cache miss
Hibernate: select cats0_.CAT_UUID as CAT1_2_, cats0_.CAT_UUID as CAT1_1_, cats0_.CAT_NAME as CAT2_9_1_, cats0_.PERSON_UUID as PERSON3_9_1_, person1_.PERSON_UUID as PERSON1_0_, person1_.FIRST_NAME as FIRST2_46_0_ from CAT cats0_ inner join PERSON person1_ on cats0_.PERSON_UUID=person1_.PERSON_UUID where cats0_.CAT_UUID=?
[11-07-05 19:25:14](F)<238>[TransactionalCache ]{10} caching: com.test.services.person.Person.cats#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:14](F)<239>[TransactionalCache ]{10} cache lookup: com.test.services.person.Person#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:14](F)<240>[TransactionalCache ]{10} cache hit
[11-07-05 19:25:14](F)<241>[TransactionalCache ]{10} cache lookup: com.test.services.person.Person.cats#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:14](F)<242>[TransactionalCache ]{10} cache miss
Hibernate: select cats0_.CAT_UUID as CAT1_2_, cats0_.CAT_UUID as CAT1_1_, cats0_.CAT_NAME as CAT2_9_1_, cats0_.PERSON_UUID as PERSON3_9_1_, person1_.PERSON_UUID as PERSON1_0_, person1_.FIRST_NAME as FIRST2_46_0_ from CAT cats0_ inner join PERSON person1_ on cats0_.PERSON_UUID=person1_.PERSON_UUID where cats0_.CAT_UUID=?
[11-07-05 19:25:14](F)<243>[TransactionalCache ]{10} caching: com.test.services.person.Person.cats#6A6886761A914AF78725EC79E32B2771
Hibernate: select cats0_.CAT_UUID as CAT1_2_, cats0_.CAT_UUID as CAT1_1_, cats0_.CAT_NAME as CAT2_9_1_, cats0_.PERSON_UUID as PERSON3_9_1_, person1_.PERSON_UUID as PERSON1_0_, person1_.FIRST_NAME as FIRST2_46_0_ from CAT cats0_ inner join PERSON person1_ on cats0_.PERSON_UUID=person1_.PERSON_UUID where cats0_.CAT_UUID=?
[11-07-05 19:25:14](F)<244>[TransactionalCache ]{10} cache lookup: com.test.services.person.Person#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:14](F)<245>[TransactionalCache ]{10} cache hit
[11-07-05 19:25:14](F)<246>[TransactionalCache ]{10} cache lookup: com.test.services.person.Person.cats#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:14](F)<247>[TransactionalCache ]{10} cache miss
[11-07-05 19:25:14](F)<248>[TransactionalCache ]{10} caching: com.test.services.person.Person.cats#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:14](F)<249>[TransactionalCache ]{10} cache lookup: com.test.services.person.Person#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:14](F)<250>[TransactionalCache ]{10} cache hit
[11-07-05 19:25:14](F)<251>[TransactionalCache ]{10} cache lookup: com.test.services.person.Person.cats#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:14](F)<252>[TransactionalCache ]{10} cache miss
Hibernate: select cats0_.CAT_UUID as CAT1_2_, cats0_.CAT_UUID as CAT1_1_, cats0_.CAT_NAME as CAT2_9_1_, cats0_.PERSON_UUID as PERSON3_9_1_, person1_.PERSON_UUID as PERSON1_0_, person1_.FIRST_NAME as FIRST2_46_0_ from CAT cats0_ inner join PERSON person1_ on cats0_.PERSON_UUID=person1_.PERSON_UUID where cats0_.CAT_UUID=?
[11-07-05 19:25:14](F)<253>[TransactionalCache ]{10} caching: com.test.services.person.Person.cats#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:15](F)<254>[TransactionalCache ]{10} cache lookup: com.test.services.person.Person#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:15](F)<255>[TransactionalCache ]{10} cache hit
[11-07-05 19:25:15](F)<256>[TransactionalCache ]{10} cache lookup: com.test.services.person.Person.cats#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:15](F)<257>[TransactionalCache ]{10} cache miss
Hibernate: select cats0_.CAT_UUID as CAT1_2_, cats0_.CAT_UUID as CAT1_1_, cats0_.CAT_NAME as CAT2_9_1_, cats0_.PERSON_UUID as PERSON3_9_1_, person1_.PERSON_UUID as PERSON1_0_, person1_.FIRST_NAME as FIRST2_46_0_ from CAT cats0_ inner join PERSON person1_ on cats0_.PERSON_UUID=person1_.PERSON_UUID where cats0_.CAT_UUID=?
[11-07-05 19:25:15](F)<258>[TransactionalCache ]{10} caching: com.test.services.person.Person.cats#6A6886761A914AF78725EC79E32B2771
[11-07-05 19:25:15](F)<259>[TransactionalCache ]{10} cache lookup: com.test.services.person.Cat#FE2093DF686743F8B5DD9A355B4406D1
Hibernate: delete from CAT where CAT_UUID=?
[11-07-05 19:25:15](F)<260>[TransactionalCache ]{10} cache hit
Hibernate: delete from PERSON where PERSON_UUID=?