Results 1 to 2 of 2
  1. #1
    Albert is offline Senior Member
    Join Date
    Jun 2007
    Rep Power

    Default Mapping of class Association with hibernate

    Hello people, I need to do map to a class of association

    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 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.


  2. #2
    Eric is offline Senior Member
    Join Date
    Jun 2007
    Rep Power

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 11:04 PM
  2. Help with image mapping
    By coco in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 05:06 AM
  3. Replies: 0
    Last Post: 07-16-2007, 09:45 PM
  4. About servlet-mapping
    By Heather in forum Java Servlet
    Replies: 1
    Last Post: 07-14-2007, 07:00 PM
  5. Replies: 2
    Last Post: 06-30-2007, 04:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts