-->
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.  [ 3 posts ] 
Author Message
 Post subject: Help regardin Hibernate mapping
PostPosted: Wed Aug 31, 2005 7:47 am 
Newbie

Joined: Wed Aug 31, 2005 7:39 am
Posts: 2
I am new to hibernate. I want help/reference for the following situation

I have class A and its corresponding hbm.xml file. Individually it is working fine.

I have another class B and its corresponding hbm.xml file. Individually it is also working fine.

Please note that Class A and B are not related to each other in any way

I want to define class C like
public Class C{
private A a;
private B b;

getter and setter methods.

}
Now I want to define hbm.cfg.xml file for this. So that
session.save(objC) will save both A and B (containing classes) in one shot.
What type of mapping will be this?
Plz guide me. How to define mapping file.


Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
Hibernate3.0
Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject: Class C is not necessarily needs tobe mapped.
PostPosted: Wed Aug 31, 2005 9:33 am 
Newbie

Joined: Wed Aug 31, 2005 7:24 am
Posts: 3
Location: Jakarta Indonesia
As you've mentioned that Class A and B is not related to each other in any way, So i assumed that Class C do not represent one-to-one or one-to-many or many-to-one or many-to-many association between A and B.

If my assumption is correct, then, Class C is only a helper class that dont need tobe mapped into database.

If you wish to save Class A and B at the same time by the help of Class C,
just simply create a method, let say "saveAB" in Class C.

Code:
public class C {

   private A a;
   private B b;

   // getter setter goes here.

   public void saveAB() {
     // routine to save A instance
     // routine to save B instance
   }
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 10:00 am 
Newbie

Joined: Wed Aug 31, 2005 7:39 am
Posts: 2
Hi,
Yes you have rightly and exactly understood my requirement.

1) Problem is though class C is not mapped to the database it is not just a helper class. It is logically grouping the attributes in A and B. SOme of hte things will go to table A some of the things to table B. they are not related in the sense that they dont have FK or PK relationship among each other and with A
2) Even then I very much liked your idea. I was just about to implement it and then I realised the A ,B and C are not in data access layer. They don't know underlying dataaccess layer implemenation. So we can't simply call hibernate API. like
public saveAB(){

session.save(A);// They don't have access to hibernate API
session.save(B);
}

Thanks a lot for your reply. Plz provide further assistance


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