Hibernate - inheritance

160 Views Asked by At

I have a super class called userDetailsSuper which is mapped to another table called Address.

@Entity
@Table (name = "USER_DETAILS_SUPER")
@Inheritance (strategy = InheritanceType.JOINED )
public class UserDetailsSuper 
{
  private long userDetailsSuperID;  
  private long phone;
  private Set<Address> addressSet;

 @OneToMany (mappedBy = "userDetailsSuper")
 public Set<Address> getAddressSet() {
return addressSet;
}

public void setAddressSet(Set<Address> addressSet)
{
this.addressSet = addressSet;
}
}

 Address table:
 @Entity
 @Table(name="ADDRESS")
 public class Address
{
 private long address_ID;
 private UserDetailsSuper userDetailsSuper;

@ManyToOne
@JoinColumn (name = "USER_DETAILS_SUPER_ID", nullable = false)
public UserDetailsSuper getUserDetailsSuper() {
    return userDetailsSuper;
}
public void setUserDetailsSuper(UserDetailsSuper userDetailsSuper) {
    this.userDetailsSuper = userDetailsSuper;
}
 }

//sub class
public UserDetails extends UserDetailsSuper
{
}

When I try to insert into the child table, data is inserted in the child class and super class but not in the mapped address class.

I think I'm missing some mapping... Kindly help

1

There are 1 best solutions below

0
On

Define this in your "UserDetailsSuper" Entity.

@OneToMany(cascade={CascadeType.ALL}) @JoinColumn(name="USER_DETAILS_SUPER_ID")

Follow this example http://viralpatel.net/blogs/hibernate-one-to-many-annotation-tutorial/)