-->
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.  [ 4 posts ] 
Author Message
 Post subject: Composite key woes
PostPosted: Fri Feb 27, 2004 3:53 pm 
Beginner
Beginner

Joined: Wed Jan 28, 2004 3:42 pm
Posts: 36
Hi all,

We are using Hibernate 2.1 with Oracle 9i. The ERD is virtually customer driven so we have little influence on legacy and third party design.

That said, Hibernate has proven to be very flexible. We are encountering the following problem though (contrived example):

We have the following two reference objects: PTA (account) and Organization:

<class
name="PTA"
table="IMIHS_PTA_T">

<composite-id name="comp_id" class="PTAPK">
<key-property
name="finCoaCd"
column="FIN_COA_CD"
/>
<key-property
name="project"
column="PROJECT"
/>
</composite-id>

bla bla

<!-- associations -->
<many-to-one name="organization" class="Organization" cascade="none" update="false" insert="false">
<column name="FIN_COA_CD" />
<column name="ORG_CD" />
</many-to-one>

</class>

<class
name="Organization"
table="IMIHS_ORG_T">

<composite-id name="comp_id" class="OrganizationPK">
<key-property
name="finCoaCd"
column="FIN_COA_CD"
/>
<key-property
name="orgCd"
column="ORG_CD"
/>
</composite-id>
</class>

We need the "update=false insert=false" as FIN_COA_CD is a repeated column, now this work fine in the user application where we don't want reference data to be modified from the business object perspective, however in the adminstrative interface we want to modify these, for instance insert a new PTA with relationship to Organization intact. Hence we need to discard "update=false insert=false" but we cannot because of the repeated columns. One possible solution to this problem is to have two sets of mapping files for PTA, the normal one as illiustrated above and another one where the Organization property is replace by a orgCd string property so we can atleast save the orgCd to the PTA table. However, this presents two problems: a) we would have two discrete files to maintain b) it might be impossible for Hibernate to have two mapping distinct mapping files referring to the same data (locking & integrity issues?) - we have not tried this.

Is there any other solution to this problem? If not, is the proposed solution a solution at all?

Thank you for all the help and support from Gavin and his team thus far!

Cheers,
Peter


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2004 3:57 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
(1) you would need two SessionFactory instances
(2) it is possible to manipulate mapping douments using Configuration.getClassMapping()

Those two things together should solve yr problem.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2004 4:53 pm 
Beginner
Beginner

Joined: Wed Jan 28, 2004 3:42 pm
Posts: 36
Hi Gavin,

Thank you for enlightening response! I used my junit testcase to quickly test your suggestion:

public void setUp()
throws Exception
{
super.setUp();
log.info("Doing ReferencePopulation.setUp()");
PersistentClass pta = getCfg().getClassMapping(PTA.class);
Property orgPTA = pta.getProperty("organization");
log.info("organization property insertable: " + orgPTA.isInsertable() + " updatable " + orgPTA.isUpdateable());
orgPTA.setUpdateable(true);
orgPTA.setInsertable(true);
pta.addProperty(orgPTA); ---> with or without this line
log.info("Done changing mapped class insert and update fields");
}

However, the insert statement still does not insert an orgCd, it acts just like it did without this extra code, in other words, adhering to the update=false and insert=false attributes in the mapping file. Did I misunderstand ?

Thanks much,
Peter


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2004 5:08 pm 
Beginner
Beginner

Joined: Wed Jan 28, 2004 3:42 pm
Posts: 36
PS. Just out of curiosity I tried rebuilding the sessionFactory after making the changes to those properties in my setUp():

PersistentClass pta = getCfg().getClassMapping(PTA.class);
Property orgPTA = pta.getProperty("organization");
log.info("organization property insertable: " + orgPTA.isInsertable() + " updatable " + orgPTA.isUpdateable());
orgPTA.setUpdateable(true);
orgPTA.setInsertable(true);
pta.addProperty(orgPTA);
setSessions(getCfg().buildSessionFactory());

However, this results (expected) in the same error one encounters excluding the update and insert attributes (or setting to true) in the mapping file:

<many-to-one name="organization" class="Organization" cascade="true" update="true" insert="false">

[junit] Repeated column in mapping for class PTA should be mapped with insert="false" update="false": FIN_COA_CD
[junit] net.sf.hibernate.MappingException: Repeated column in mapping for class PTA should be mapped with insert="false" update="false": FIN_COA_CD

Perhaps I completely misunderstood the solution :)

Thanks!
Peter


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

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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.