Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-06-2007, 05:00 AM
Senior Member
 
Join Date: Jun 2007
Posts: 114
Albert is on a distinguished road
Mapping of class Association with hibernate
Hello people, I need to do map to a class of association

Code:
public class ClassA { private Integer id_A = new Integer(-1); //collection B } public class ClassB{ private Integer id_B = new Integer(-1); // collection A } public class ClassAB { // many-to-many with extra attributes private A a; // attribute of the type of the A class or could be of the type of id_A, would be PK and FK private B b;// attribute of the type of class B or could be of the type of id_B, would be PK and FK private String extraAttribute; private Date date; }
The problem that appears to me is that the mapping alternatives, that offer hibernate for relations many to many, when the intermediate class has additional attributes to the primary keys (pk own and fk other people's), also happen to be part of the key, and I did not find as it would have to be the method to insert a new object to this collection, and to be able to assign to him to values to the additional attributes (ExtraAttribute and date), in addition in my model these attributes they would not be primary key and they could later be, therefore null or to be loaded if outside necessary (thing q the mapping offered by hibernate conditions to being it, PK everything).

The q I made to solve it momentarily is to create this intermediate class, and in the mapping (ClassAB.hbm.xml) to make use of composite-you go with key-many-to-one for the traditional FK and property for the remaining attributes. Next to this, a method that does saveORupdate of the instance of ClassAB, also methods that give back collection to me of A and B (in this case would use ArrayList) to add to the same ones, but the problem of this is that he is everything very artisan.

Albert
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-06-2007, 07:27 AM
Senior Member
 
Join Date: Jun 2007
Posts: 111
Eric is on a distinguished road
Hi Albert, please check this link:

MCS Wiki :: Development/Java & J2EE/Hibernate/Mapping

Greetings
Eric
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with image mapping coco AWT / Swing 1 08-07-2007 05:06 AM
mapping servlets in user defined xml file and invoking them praneeth Advanced Java 0 07-16-2007 09:45 PM
About servlet-mapping Heather Java Servlet 1 07-14-2007 07:00 PM
org.hibernate.DuplicateMappingException: Duplicate class/entity mapping project Ed Database 2 07-04-2007 06:17 AM
org.hibernate.ejb.Version <clinit> INFO: Hibernate EntityManager 3.2.0.CR1 Heather Database 2 06-30-2007 04:01 PM


All times are GMT +3. The time now is 07:42 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org