0

我有一个名为的超类userDetailsSuper,它映射到另一个名为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
{
}

当我尝试插入子表时,数据被插入到子类和超类中,但不在映射地址类中。

我想我错过了一些映射......请帮忙

4

1 回答 1

0

在您的“UserDetailsS​​uper”实体中定义它。

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

按照这个例子 http://viralpatel.net/blogs/hibernate-one-to-many-annotation-tutorial/

于 2013-09-11T16:09:46.047 回答