-->
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.  [ 2 posts ] 
Author Message
 Post subject: Mapping question
PostPosted: Fri Jun 02, 2006 5:24 am 
Newbie

Joined: Thu Apr 06, 2006 10:16 am
Posts: 6
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
Hibernate 3.1.3

Hello, people

I have a question related to the mapping of two tables, A and B, which have the almost the same columns (table B has all the columns of table A plus one column of it's own). Table A represents some of the application data, table B represents temporary data.

Starting from this point I want to create a hibernate mapping (hbm files) to have mapped this two tables but to not duplicate the mapping code (and also to not have duplicate code inside the generated POJOs). It would be nice that the generated B bean can use the A bean's properties.

Also i must mention that these two tables can't be related one to the other (no foreign key can be created between these two tables).

I tried first with union-subclass by subclassing B from A, and if i have in B a record from A with the same ID, but with different data, when i try to load this record from B, Hibernate throws and error : duplicate data in session having the same identifier (B beeing derived from A).

I cannot solve this problem using joined-subclass because no foreign keys can de defined between these tables.

For now the problem is solved through the existence of separate beans (A and B), but I got duplicated code.

There can be another solution or just maybe is bad DB tables design?

Can anybody help me in this issue?

Thank you

Daniel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 02, 2006 8:06 am 
Beginner
Beginner

Joined: Tue Nov 22, 2005 5:33 am
Posts: 31
If you would use Hibernate annotations all of the mapping configuration would be in the classes, so if you would extend one class the mapping would follow and no mapping conf need to be duplicated:

Code:
@Entity
public class Class1 implements Serializable {
       long field1;
       long id;
        @Id
   @GeneratedValue(strategy=GenerationType.SEQUENCE)
   public Long getId() {
      return id;
   }
        public void setId(Long id) {
      this.id = id;
   }
       
        public Long getField1() {
      return id;
   }
        public void setField1(Long id) {
      this.id = id;
   }
}
@Entity
public class Class2 extends Class1 {
}

_________________
Emil
Don't forget to rate, I'm desperate!


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