Hello, I've scoured the net for an answer but I haven't been able to find one, I guess I must a newb but here it goes. I will try to be as clear as possible.
I have a class A which has a composite key identifier:
Its impl would look like:
Code:
public class A {
public final static class Id implements Serializable {
public Long aId1;
public Long aId2;
}
private Id id;
public Id getId() { return id; }
public void setId(Id id) { this.id = id; }
<... getters/setters/other code here ...>
}
and its mapping a trivial:
Code:
<class name="A" table="A_TBL">
<composite-id class="A$Id" name="id">
<key-property access="field" column="id1" name="aId1" type="long"/>
<key-property access="field" column="id2" name="aId2" type="long"/>
</composite-id>
</class>
Simple right? Well I want to create a one-to-one mapping to this class without having to change the implementation code or the mapping file (they are generated) from a class B:
B is even more simple, although maybe I'm missing something:
Code:
public class B {
private A.Id id;
private A a;
public A.Id getId() { return id; }
public void setId(A.Id id) { this.id = id; }
public A getA() { return a; }
public void setA(A a) { this.a = a; }
<... getters/setters/other code here ...>
}
And here is the mapping, and where I think the error lies:
Code:
<class name="B" table="B_TBL">
<id name="id" type="A$Id">
<column name="id1"/>
<column name="id2"/>
<generator class="foreign">
<param name="property">a</param>
</generator>
</id>
<one-to-one name="a" class="A" constrained="true"/>
</class>
Ok for me this seems simple enough but now I can successfully add the mapping files to the session factory (I use addURL()) but when I attempt to build the session factory, I get this exception:
org.hibernate.MappingException: identifier mapping has wrong number of columns: dummy.B type: dummy.A$Id
at org.hibernate.mapping.RootClass.validate(RootClass.java:194)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1102)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.jav
a:1287)
...
Now I've looked a little into the code and well there is something I don't understand. In my B mapping class I want the primary key to be 2 columns wide like in A (duh same key ;)). But well the type of the $Id class is SerializableType and well the getColumnSpan() of it always returns 1 (inhereted from NullableType). Is this a possible bug?
If anyone can please help I would be most appreciative. Thanks again :)