Results 1 to 2 of 2
- 06-06-2007, 04:00 AM #1
Senior Member
- Join Date
- Jun 2007
- Posts
- 114
- Rep Power
- 0
Mapping of class Association with hibernate
Hello people, I need to do map to a class of association
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).Java 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 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:rolleyes:
- 07-06-2007, 06:27 AM #2
Senior Member
- Join Date
- Jun 2007
- Posts
- 111
- Rep Power
- 0
Hi Albert, please check this link:
MCS Wiki :: Development/Java & J2EE/Hibernate/Mapping
Greetings
Eric
Similar Threads
-
org.hibernate.DuplicateMappingException: Duplicate class/entity mapping project
By Ed in forum JDBCReplies: 4Last Post: 05-13-2011, 10:04 PM -
Help with image mapping
By coco in forum AWT / SwingReplies: 1Last Post: 08-07-2007, 04:06 AM -
mapping servlets in user defined xml file and invoking them
By praneeth in forum Advanced JavaReplies: 0Last Post: 07-16-2007, 08:45 PM -
About servlet-mapping
By Heather in forum Java ServletReplies: 1Last Post: 07-14-2007, 06:00 PM -
org.hibernate.ejb.Version <clinit> INFO: Hibernate EntityManager 3.2.0.CR1
By Heather in forum JDBCReplies: 2Last Post: 06-30-2007, 03:01 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks