Hibernate Version 2.1
Using Spring Framework
I have a table called CLIENT which can have many relationships with other clients. For instance, a client may be married to another client.
Table Structure:
CLIENT:
Code:
CLIENT_SEQ NUMBER PRIMARY KEY
NAME VARCHAR2(100)
CLIENT_RELATIONSHIP:Code:
CLIENT_SEQ_SOURCE NUMBER PRIMARY KEY FOREIGN KEY
CLIENT_SEQ_TARGET NUMBER PRIMARY KEY FOREIGN KEY
RELATIONSHIP_TYPE VARCHAR2 PRIMARY KEY
DEPENDANT CHAR(1)
JAVA Classes:Code:
public class Client
{
private Long id;
private String name;
private Set relationships = new HashSet();
}
public class Relationship
{
private Long clientSeq;
private RelationshipType relationshipType;
private Boolean dependant;
}
Mapping file:Code:
<class name="au.com.sealcorp.apm.client.Client" table="CLIENT">
<id name="id" type="long" column="CLIENT_SEQ">
<generator class="sequence">
<param name="sequence">OTUSER.ASGARD_ACCOUNT_NUMBER</param>
</generator>
</id>
<property name="name"/>
<set name="relationships" table="CLIENT_RELATIONSHIP">
<key column="CLIENT_SEQ_SOURCE"/>
<composite-element class="au.com.sealcorp.apm.client.Relationship">
<property name="relationshipType" column="CLIENT_RELATIONSHIP_TYPE" type="string"/>
<property name="dependant" column="DEPENDANT"/>
<many-to-one name="clientSeq" column="CLIENT_SEQ_TARGET" class="au.com.sealcorp.apm.client.Client"/>
</composite-element>
</set>
</class>
Code:Code:
Client client = new Client();
client.setName("My client");
Relationship relationship = new Relationship();
relationship.setClientSeq(new Long(566171));
relationship.setRelationshipType(RelationshipType.SPOUSE);
relationship.setDependant(new Boolean(false));
client.addRelationship(relationship);
clientDAO.save(client);
Result:
When I execute the above code, I get the following exception:
12:37:42,540 DEBUG [SessionImpl] flushing session
12:37:42,540 DEBUG [SessionImpl] Flushing entities and processing referenced collections
12:37:42,550 DEBUG [SessionImpl] Collection found: [au.com.sealcorp.apm.client.Client.addresses#566190], was: [<unreferenced>]
12:37:42,550 DEBUG [SessionImpl] Collection found: [au.com.sealcorp.apm.client.Client.relationships#566190], was: [<unreferenced>]
12:37:42,550 DEBUG [SessionImpl] Processing unreferenced collections
12:37:42,550 DEBUG [SessionImpl] Scheduling collection removes/(re)creates/updates
12:37:42,550 DEBUG [SessionImpl] Flushed: 1 insertions, 0 updates, 0 deletions to 1 objects
12:37:42,550 DEBUG [SessionImpl] Flushed: 2 (re)creations, 0 updates, 0 removals to 2 collections
12:37:42,550 DEBUG [Printer] listing entities:
12:37:42,560 ERROR [BasicPropertyAccessor] IllegalArgumentException in class: au.com.sealcorp.apm.client.Client, getter method of property: id
12:37:42,560 DEBUG [HibernateTransactionManager] Initiating transaction rollback on commit exception
org.springframework.orm.hibernate.HibernateSystemException: IllegalArgumentException occurred calling getter of au.com.sealcorp.apm.client.Client.id; nested exception is net.sf.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of au.com.sealcorp.apm.client.Client.id
net.sf.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of au.com.sealcorp.apm.client.Client.id
at net.sf.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:110)
at net.sf.hibernate.persister.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:306)
at net.sf.hibernate.proxy.HibernateProxyHelper.getIdentifier(HibernateProxyHelper.java:48)
at net.sf.hibernate.type.EntityType.toString(EntityType.java:84)
at net.sf.hibernate.type.ComponentType.toString(ComponentType.java:248)
at net.sf.hibernate.type.PersistentCollectionType.toString(PersistentCollectionType.java:82)
at net.sf.hibernate.impl.Printer.toString(Printer.java:49)
at net.sf.hibernate.impl.Printer.toString(Printer.java:82)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2277)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2235)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at org.springframework.orm.hibernate.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:386)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:316)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:211)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:138)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:148)
at $Proxy0.save(Unknown Source)
at au.com.sealcorp.apm.Main.main(Main.java:76)
Caused by:
java.lang.IllegalArgumentException: object is not an instance of declaring class
at java.lang.reflect.Method.invoke(Native Method)
at net.sf.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:96)
... 17 more
12:37:42,590 DEBUG [HibernateTransactionManager] Rolling back Hibernate transaction on session [net.sf.hibernate.impl.SessionImpl@108881]
Your help in resolving this is very much appreciated!
Ray