-->
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.  [ 4 posts ] 
Author Message
 Post subject: Problem with design of POJO classes and their mappings
PostPosted: Wed Aug 30, 2006 12:26 pm 
Beginner
Beginner

Joined: Sat Oct 08, 2005 2:13 am
Posts: 47
Hello

Hibernate version:3.1

Mapping documents:Annotation

Name and version of the database you are using:MySql 4.5

I designed my database to be multilanguage, something like this:

table Patient_Info (id, admit_date, status, type, discharge_date)
table Patient_info_locale (patient_id, locale_id, name, family)

[name and family in second table will be inserted in different languages]

at first, I create a class for each and made a master/detail relation between them. but it made many problems for other programmers. using this strategy is very hard. because you always should challenge with the collections and there are many tables in the databse like this one. i want my programmers work with only one class not a class with a collection. I mean if I need some info from a patient I use PatientInfoLocale class and access to all attribute of patient with advantages of inheritance. I am detested using PatientInfo class and then load its collection (eg. patientInfo.getPatientInfoLocales() )

in my opinion, both patient_info and patient_info_locale are identical conceptually. so I decided to use joined inheritance strategy.

now, It buffled me. because in this strategy the subtype has the same primary key in the super type. so , for example, if the information of a patient being inserted in two different language (for example English and Russian) the primary key constraint will violated and insertion will failed.
what will happen on locale_id?

is there any other way than inheritance to solve this problem? for exmple consider these classes:

Code:

@Entity
@Table(name="patient_info")
public class PatientInfo implements Serializable {
   @Id
   private long id;

   //rest of the codes
}

@Entity
@Table(name="patient_info_locale")
@IdClass(PatientInfoLocalePk.class)
public class PatientInfoLocale extends PatientInfo {

    @Id
    private long id;
    @Id
    private int localeId;


   //rest of the codes
}



but in second table there is no field of parent table (except id as a foreign key)

how can I manage it? please help me out.

thank you so much in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 11, 2006 8:18 am 
Beginner
Beginner

Joined: Sat Oct 08, 2005 2:13 am
Posts: 47
Any Idea?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 12, 2006 11:16 am 
Newbie

Joined: Tue Sep 12, 2006 10:18 am
Posts: 4
Location: Porto / Portugal
I'm quite newbie in this... but couldn't you make a one to many mapping using a List in the Patient_Info class?

Code:

@Entity
@Table(name="patient_info")
public class PatientInfo implements Serializable {
   @Id
   private long id;

@OneToMany( mappedBy="id", cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
  private List <PatientInfoLocale> patientInfoLocale;
   //rest of the codes
}

@Entity
@Table(name="patient_info_locale")
@IdClass(PatientInfoLocalePk.class)
public class PatientInfoLocale extends PatientInfo {

    @Id
    private long id;
    @Id
    private int localeId;

   @ManyToOne
   @JoinColumn(name = "id", referencedColumnName="id")
   private PatientInfo;

   //rest of the codes
}



something like this... !?!?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 13, 2006 12:56 am 
Beginner
Beginner

Joined: Sat Oct 08, 2005 2:13 am
Posts: 47
ht wrote:
I'm quite newbie in this... but couldn't you make a one to many mapping using a List in the Patient_Info class?


yes, I could and now my project goes this way, but as I said before, I want to use inheritance advantages and I want my developers work with less complexity codes.

thanks


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