Hi,
I have to map a unidirectional many-to-many relationship on a legacy database. I have been given the POJOs and the database and I have to create the mappings without modifying the entities (as much as possible) or the database. My problem is that I have not been able to map a relationship table that has a PK and an Index column along with the keys from the association tables! The index column is not null as well.
These entities have been mapped using JDO to the same database earlier.
The parent class
Code:
public class Owner extends Persistent{
private Long id; //actually defined in Persistent
private List elements = new ArrayList();
//getters, setters and other stuff
}
the child class
Code:
public class Element extends Persistent{
private Long id; //actually defined in Persistent
//no relation back to Parent
//getters, setters and other stuff
}
The association table OWNER_ELEMENT_
Code:
ID NUMBER (sequence)
OWNER_ID NUMBER
ORDER_INDEX NUMBER -- (the index column which is incremented whenever owner is asscoaited with another element)
ELEMENT_ID
The mapping that don't seem to work for inserts or updates
Code:
<subclass name="Owner" extends="Persistent"
discriminator-value="99999">
<idbag name="elements" table="OWNER_ELEMENT_" cascade="all">
<collection-id column="ID" type="long">
<generator class="sequence">
<param name="sequence">PERSISTENT_UID_SEQ</param>
</generator>
</collection-id>
<key column="OWNER_ID" />
<many-to-many column="ELEMENT_ID" class="Element" />
</idbag>
<join fetch="select" table="OWNER_">
<!-- Primary Key mapping -->
<key column="UID_" />
<property name="blah" type="java.lang.String" column="BLAH_" />
</join>
</subclass>
Whenever I try to add a new association by simply adding Element to Owner.elements, I get an oracle exception that says ORDER_INDEX cannot be null.
Therefore, how do I map the index column and get the index behaviour out of it? Or do I use List, then how do I generate the ID column value?
Thanks in advance,
Raj