How to store some of the entity's values in another table using hibernate?
        Posted  
        
            by nimcap
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by nimcap
        
        
        
        Published on 2010-04-06T14:25:21Z
        Indexed on 
            2010/04/06
            15:13 UTC
        
        
        Read the original article
        Hit count: 365
        
Hi guys, is there a simple way to persist some of the fields in another class and table using hibernate.
For example, I have a Person class with name, surname, email, address1, address2, city, country fields. I want my classes to be:
public class Person
{
   private String name;
   private String surname;
   private String email;
   private Address address;
   // ..
}
public class Address
{
   private Person person; // to whom this belongs
   private String address1;
   private String address2;
   private String city;
   private Address country;
   // ..
}
and I want to store Address in another table. What is the best way to achieve this?
Edit: I am using annotations. It does not have to be the way I described, I am looking for best practices.
PS. If there is a way to make Address immutable (to use as a value object) that is even better, or maybe not because I thought everything from wrong perspective :)
© Stack Overflow or respective owner