Hi folks,
I'm getting the following strange behaviour:
After retrieving a persistent object I call the toString() method on this object and the output shows the expected value in the uuid (primary key) field. On the next line I call getUuid() and it returns null.
To give a bit more detail, the object that is giving me the problem is part of an association of objects. I have a Role object and a Right object which have a many-to-many association but this is modelled in the DB and the Java code as two many-to-one associations using an intermediary class called RoleRight.
The problem occurs when I retrieve a Role by uuid and then call Role.getRights() to return a set of Right objects. It is these Right objects that return null from their getUuid() method. The runtime type of Right is a proxy. The other fields of the Right object return correctly, just seems to be the id field. It's a mystery to me.
I hope that's enough information. Any help would be very much appreciated.
Kevin
Hibernate version:
3.1.3
Mapping documents:
Trimmed for clarity
Code:
<hibernate-mapping>
<class
name="user.model.Role"
table="ROLES">
<id
name="uuid"
type="string">
<column
name="UUID"
length="32" />
<generator class="assigned" />
</id>
<set
name="roleRights"
inverse="true"
cascade="all-delete-orphan"
lazy="false">
<key column="ROLEID" />
<one-to-many class="user.model.RoleRight" />
</set>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class
name="user.model.Right"
table="RIGHTS">
<id
name="uuid"
type="string">
<column
name="UUID"
length="32" />
<generator class="assigned" />
</id>
<set
name="roleRights"
inverse="true"
cascade="all-delete-orphan"
lazy="false">
<key column="RIGHTID" />
<one-to-many class="user.model.RoleRight" />
</set>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class
name="user.model.RoleRight"
table="ROLERIGHTS">
<id
name="uuid"
type="string">
<column
name="UUID"
length="32" />
<generator class="assigned" />
</id>
<many-to-one
name="role"
class="user.model.Role"
fetch="select">
<column
name="ROLEID"
length="32"
not-null="true" />
</many-to-one>
<many-to-one
name="right"
class="user.model.Right"
fetch="select">
<column
name="RIGHTID"
length="32"
not-null="true" />
</many-to-one>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():This is the code from the Generic Hibernate DAO that retrieves objects by id. It is based on the example on the Hibernate site.
Code:
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
public T findById(ID id, boolean lock) {
NullArgumentException.throwIfNull("id", id);
try {
T entity;
if (lock) {
entity = (T) getSessionFactory()
.getCurrentSession()
.get(getPersistentClass(), id, LockMode.UPGRADE);
} else {
entity = (T) getSessionFactory()
.getCurrentSession()
.get(getPersistentClass(), id);
}
return entity;
} catch (HibernateException e) {
throw SessionFactoryUtils.convertHibernateAccessException(e);
}
}
Full stack trace of any exception that occurs:None
Name and version of the database you are using:Oracle 10g
The generated SQL (show_sql=true):Hibernate: select role0_.UUID as UUID21_0_, role0_.ROLESEQ as ROLESEQ21_0_, role0_.ROLETYPEID as ROLETYPEID21_0_, role0_.CODE as CODE21_0_, role0_.CAPTION as CAPTION21_0_, role0_.VALIDFROM as VALIDFROM21_0_, role0_.VALIDUNTIL as VALIDUNTIL21_0_, role0_.STATUS as STATUS21_0_, role0_.MODIFIEDBY as MODIFIEDBY21_0_, role0_.MODIFICATIONTIME as MODIFIC10_21_0_ from ROLES role0_ where role0_.UUID=?
Hibernate: select rolerights0_.ROLEID as ROLEID1_, rolerights0_.UUID as UUID1_, rolerights0_.UUID as UUID23_0_, rolerights0_.ROLERIGHTSEQ as ROLERIGH2_23_0_, rolerights0_.ROLEID as ROLEID23_0_, rolerights0_.RIGHTID as RIGHTID23_0_, rolerights0_.VALIDFROM as VALIDFROM23_0_, rolerights0_.VALIDUNTIL as VALIDUNTIL23_0_, rolerights0_.STATUS as STATUS23_0_, rolerights0_.MODIFIEDBY as MODIFIEDBY23_0_, rolerights0_.MODIFICATIONTIME as MODIFICA9_23_0_ from ROLERIGHTS rolerights0_ where rolerights0_.ROLEID=?
Hibernate: select right0_.UUID as UUID24_0_, right0_.RIGHTSEQ as RIGHTSEQ24_0_, right0_.CODE as CODE24_0_, right0_.CAPTION as CAPTION24_0_, right0_.QUALIFIERS as QUALIFIERS24_0_, right0_.BILLABLE as BILLABLE24_0_, right0_.VALIDFROM as VALIDFROM24_0_, right0_.VALIDUNTIL as VALIDUNTIL24_0_, right0_.STATUS as STATUS24_0_, right0_.MODIFIEDBY as MODIFIEDBY24_0_, right0_.MODIFICATIONTIME as MODIFIC11_24_0_ from RIGHTS right0_ where right0_.UUID=?
Hibernate: select rolerights0_.RIGHTID as RIGHTID1_, rolerights0_.UUID as UUID1_, rolerights0_.UUID as UUID23_0_, rolerights0_.ROLERIGHTSEQ as ROLERIGH2_23_0_, rolerights0_.ROLEID as ROLEID23_0_, rolerights0_.RIGHTID as RIGHTID23_0_, rolerights0_.VALIDFROM as VALIDFROM23_0_, rolerights0_.VALIDUNTIL as VALIDUNTIL23_0_, rolerights0_.STATUS as STATUS23_0_, rolerights0_.MODIFIEDBY as MODIFIEDBY23_0_, rolerights0_.MODIFICATIONTIME as MODIFICA9_23_0_ from ROLERIGHTS rolerights0_ where rolerights0_.RIGHTID=?
Debug level Hibernate log excerpt:[/code]