JPA 2.0 Provider Hibernate

Posted by Rooh on Stack Overflow See other posts from Stack Overflow or by Rooh
Published on 2010-12-30T08:50:33Z Indexed on 2011/01/17 12:53 UTC
Read the original article Hit count: 239

Filed under:
|
|
|
|

I have very strange problem we are using jpa 2.0 with hibernate annotations based Database generated through JPA DDL is true and MySQL as Database;

i will provide some reference classes and then my porblem.

@MappedSuperclass
public abstract class Common implements serializable{
 @Id
 @GeneratedValue(strategy = GenerationType.AUTO)
 @Column(name = "id", updatable = false)
 private Long id;

 @ManyToOne
 @JoinColumn
 private Address address;
        //with all getter and setters
        //as well equal and hashCode

}

@Entity
public class Parent extends Common{
         private String name;
         @OneToMany(cascade = {CascadeType.MERGE,CascadeType.PERSIST}, mappedBy = "parent") 
         private List<Child> child;
         //setters and rest of class
}

@Entity
public class Child extends Common{
//some properties with getter/setters
}

@Entity
public class Address implements Serializable{

 @Id
 @GeneratedValue(strategy = GenerationType.AUTO)
 @Column(name = "id", updatable = false)
 private Long id;

       private String street;
      //rest of class with get/setter

}

as in code you can see that parents and child classes extends Common class so both have address property and id , the problem occurs when change the address refference in parent class it reflect same change in all child objects in list and if change address refference in child class then on merge it will change address refference of parent as well

i am not able to figure out is it is problem of jpa or hibernate

© Stack Overflow or respective owner

Related posts about java

Related posts about hibernate