Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.05
Mapping documents:
<hibernate-mapping>
<class name="A" table="A">
<id name="a_id" column="a_id" length="30"/>
..
<bag name="bs"
inverse="true"
order-by="a_id,b_tn asc"
lazy="false">
<key column="a_id"/>
<one-to-many class="B" />
</bag>
</class>
<class name="B" table="B">
<composite-id>
<key-many-to-one name="a_id" class="A">
<column name="a_id" not-null="true" length="30"/>
</key-many-to-one>
<key-property name="b_tn">
<column name="b_tn" not-null="true" length="30"/>
</key-property>
</composite-id>
..
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Caused by: org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.att.up.prom.stac.data.EDndUserPreferences.userTn
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:119)
at org.hibernate.tuple.AbstractTuplizer.getIdentifier(AbstractTuplizer.java:103)
at org.hibernate.persister.entity.BasicEntityPersister.getIdentifier(BasicEntityPersister.java:2944)
at org.hibernate.type.EntityType.getHashCode(EntityType.java:377)
at org.hibernate.type.ComponentType.getHashCode(ComponentType.java:162)
at org.hibernate.engine.EntityKey.getHashCode(EntityKey.java:68)
at org.hibernate.engine.EntityKey.<init>(EntityKey.java:41)
at org.hibernate.engine.PersistenceContext.getDatabaseSnapshot(PersistenceContext.java:296)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:189)
at org.hibernate.event.def.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:409)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:82)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:468)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:463)
at com.whatever.Dao.updateA(Dao.java:130)
... 19 more
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60)
at java.lang.reflect.Method.invoke(Method.java:391)
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:105)
... 33 more
Name and version of the database you are using:Oracle 9
I have inherited a legacy schema (not that old but I have no control over it, God bless outsourcing).
In a nutshell, the main table has a program-assigned primary key (non-synthetic) and the secondary table has a composite primary key consisting of a foreign key field referencing the main table's primary key and another non-synthetic key field in the secondary table.
It is defined as follows:
CREATE TABLE "A"
( "A_ID" VARCHAR2(30 BYTE) NOT NULL ENABLE,
PRIMARY KEY ("A_ID") ENABLE
) ;
CREATE TABLE "B"
(
"A_ID" VARCHAR2(30 BYTE) NOT NULL ENABLE,
"B_TN" VARCHAR2(30 BYTE) NOT NULL ENABLE,
...
PRIMARY KEY ("A_ID", "B_TN") ENABLE,
CONSTRAINT "FK3D31C5A96D99FB8" FOREIGN KEY ("A_ID")
REFERENCES "A" ("A_ID") ENABLE
) ;
POJOs:
public class B
implements Comparable, Serializable
{
private String b_tn;
private String a_id;
private String blockedName;
public String getB_tn() {
return b_tn;
}
public void setB_tn(String b_tn) {
this.b_tn = b_tn;
}
public String getA_id() {
return a_id;
}
public void setA_id(String a_id) {
this.a_id = a_id;
}
public int compareTo(Object o) {
B that = (B) o;
int result = this.a_id.compareTo(that.a_id);
if (result == 0) {
result = this.b_tn.compareTo(that.b_tn);
}
return result;
}
public boolean equals(Object obj) {
if (!(obj instanceof B)) {
return false;
}
B that = (B) obj;
if (!this.a_id.equals(that.a_id)) {
return false;
}
return this.b_tn.equals(that.b_tn);
}
public int hashCode() {
return 37 * this.a_id.hashCode()
+ this.b_tn.hashCode();
}
}
public class A
implements Serializable
{
private String a_id;
private List bs;
...
public String getA_id() {
return a_id;
}
public void setA_id(String a_id) {
this.a_id = a_id;
}
public List getBs() {
return bs;
}
public void setBs(List bs) {
this.bs = bs;
}
}
I know this is not best practice but I have no control here. I thought it would be simple to map this collection, but it is killing me.
Everything looks good until I try to add a B to A.bs and persist it. Then I get the above exception. I've tried everything. I simply don't understand why this InvalidArgumentException is being thrown when attempting to invoke a simple getter through reflection. My initial thought was to cascade everything but then I saw in the DTD that <key-many-to-one> should never be cascaded. Didn't matter, failed either way.