-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Legacy n:m mapping using idbag and index column
PostPosted: Mon Jan 25, 2010 2:35 pm 
Newbie

Joined: Mon Jan 25, 2010 2:04 pm
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.