-->
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.  [ 6 posts ] 
Author Message
 Post subject: Circular mapping problem
PostPosted: Thu Sep 04, 2003 1:54 pm 
Beginner
Beginner

Joined: Thu Sep 04, 2003 1:46 pm
Posts: 20
Hello,

Our team chose to create seperate class mapping files for each Persistent class. A.hbm.xml, B.hbm.xml, C.hbm.xml, etc.

We are using Hibernate version 1.2.x.

They are then added to the Hibernate Datastore. Hibernate seems to require that the classes be added to the Datastore in a pre-defined order. Mapping exceptions occur if you add them to the datastore out of order.

If Class A depends on Class B then mapping exceptions occur if you add class A before class B.

How do you handle the case where Class A has a reference to Class B and Class B also has a reference back to Class A.

For example:

Class A has a set of Class B.
Class B has a reference to a single Class A.

We like the concept of small hbm.xml files for each class, but want to avoid duplicate class definitions and maintenance.

Is there a way to create a hbm.xml file that includes other hbm.xml files?

Is there another solution aside from creating one master hbm.xml mapping file?

Thanks in advance.


Top
 Profile  
 
 Post subject: Re: Circular mapping problem
PostPosted: Thu Sep 04, 2003 2:09 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Hibernate goes a certain length to avoid requiring ordering - so can you post a small example set of hbm.xml's (2 should be enough) that show this problem ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 2:21 pm 
Beginner
Beginner

Joined: Thu Sep 04, 2003 1:46 pm
Posts: 20
Class SigningApptDbBean:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-1.1.dtd">
<hibernate-mapping>
<class name="com.ditech.signingappt.db.SigningApptDbBean" table="pub.signing_appt">
<id name="loanNumber" type="string" column="loan_no" >
<generator class="assigned" />
</id>

<!-- .... stuff removed ...-->

<one-to-one name="loan" class="com.ditech.loanexceptions.db.LoanDbBean" />

</class>
</hibernate-mapping>





Class LoanDbBean:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-1.1.dtd">
<hibernate-mapping>

<class name="com.ditech.loanexceptions.db.LoanDbBean" table="pub.loans">
<id name="loanNumber" type="string" column="loan_no" >
<generator class="assigned" />
</id>

<!-- stuff removed ... -->

<set role="signingAppts">
<key column="loan_no" />
<one-to-many class="com.ditech.signingappt.db.SigningApptDbBean" />
</set>

</class>
</hibernate-mapping>

Then we add them to the datastore using static initialization code blocks in DAO objects.

In Class LoanDb ( a DAO ) :

datastore.storeClass(BorrowerDbBean.class);
datastore.storeClass(SigningApptDbBean.class);
datastore.storeClass(LoanDbBean.class);


In Class SigningApptDb:

datastore.storeClass(NotaryDbBean.class);
datastore.storeClass(VendorDbBean.class);
datastore.storeClass(BorrowerDbBean.class);
datastore.storeClass(LoanDbBean.class);
datastore.storeClass(SigningApptDbBean.class);

NOTE: there is code, which is not posted here, that prevents a class from being added to the datastore if it already exists in the datastore.

calling "storeClass" appears to load and parse the class hbm.xml files.

Depending on the order that I add the classes to the datastore, I receive different errors including "unmapped class" and "no persister found for class" and others.

Thanks
-bnl


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 2:48 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
I just tested your mapping with Hibernate 2 and here there were no problems.

I think that at some point that was this limitation in hibernate 1.x - but i think you need to updated to 2.x before getting the better and simpler Configuration mechanism.

Gavin?

/max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 4:24 pm 
Beginner
Beginner

Joined: Thu Sep 04, 2003 1:46 pm
Posts: 20
Thanks. What is required to convert from v 1.2.x to 2.x?

Are there major or minor code changes and can u send a link to new docs?

Does v. 2.0 allow you to change the primary key that links a one-to-one relationship?

Thank you,
-bnl


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 6:15 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
http://www.hibernate.org/68.html

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.