问题是这样的,三个表:
TAB,TAB_EX1,TAB_EX2TAB_EX1,TAB_EX2都与TAB主键关键,即TAB_EX1,TAB_EX2的主键也同时是外键关联TAB@Entity
@Table(name = "SHOP_TAB", schema = "FJCBST", uniqueConstraints = {})
@Inheritance(strategy=InheritanceType.JOINED) 
@SequenceGenerator(name="SEQ_STORE", sequenceName="SHOP_SEQ",allocationSize = 1)
public class ShopTab implements java.io.Serializable {}@Entity
@Table(name = "SHOP_LEVEL_TAB", schema = "FJCBST", uniqueConstraints = {})
@Inheritance(strategy = InheritanceType.JOINED)
@PrimaryKeyJoinColumn(referencedColumnName="SHOP_ID")
public class ShopLevelTab extends ShopTab implements java.io.Serializable {}@Entity
@Table(name = "SHOP_EX_TAB", schema = "FJCBST", uniqueConstraints = {})
@Inheritance(strategy = InheritanceType.JOINED)
@PrimaryKeyJoinColumn(referencedColumnName="SHOP_ID")
public class ShopExTab extends ShopLevelTab implements java.io.Serializable {
}
我是这样配置的,但在保存的时候出问题了,用的是HIBERNATE3.2请问我是哪配置错了,我就是想保存ShopExTab的时候,能同时插条记录到ShopTab与ShopLevelTab,且主键相同

解决方案 »

  1.   

    这样设是不是不太清晰,用@OneToOne和@PrimaryKeyJoinColumn配合是不是好一点。
      

  2.   

    而且好像也得设cascade = { CascadeType.ALL })
      

  3.   

    cascade = { CascadeType.ALL })
    请问这个在哪设呀?
      

  4.   

    在@OneToOne里有选项,你那么写好像不行。
      

  5.   

    是不行呀.
    是不是说要这样?才可以用@OneToOne呀?
    @Entity
    @Table(name = "SHOP_TAB", schema = "FJCBST", uniqueConstraints = {})
    @SequenceGenerator(name="SEQ_STORE", sequenceName="SHOP_SEQ",allocationSize = 1)
    public class ShopTab implements java.io.Serializable {}@Entity
    @Table(name = "SHOP_LEVEL_TAB", schema = "FJCBST", uniqueConstraints = {})public class ShopLevelTab implements java.io.Serializable {
         private Long shopId;
         private ShopTab shopTab;
    }@Entity
    @Table(name = "SHOP_EX_TAB", schema = "FJCBST", uniqueConstraints = {})
    public class ShopExTab implements java.io.Serializable {
         private Long shopId;
         private ShopLevelTab shopLevelTab;
    }
      

  6.   

    @Entity
    @Table(name = "SHOP_LEVEL_TAB", schema = "FJCBST", uniqueConstraints = {})public class ShopLevelTab implements java.io.Serializable {
         @Id
         private Long shopId;     @OneToOne(cascade = { CascadeType.ALL })
         @PrimaryKeyJoinColumn
         private ShopTab shopTab;
    }
      

  7.   


    public class ShopTab  implements java.io.Serializable {
         private ShopLevelTab shopLevelTab;
         @OneToOne(cascade={CascadeType.ALL}, fetch=FetchType.LAZY, mappedBy="shopTab")
         @PrimaryKeyJoinColumn
         public ShopLevelTab getShopLevelTab() {
    return shopLevelTab;
         }
    }
    public class ShopLevelTab implements java.io.Serializable {
    private ShopTab shopTab;
    private ShopExTab shopExTab;
    @Id
        @GeneratedValue(generator = "foreign")   
        @GenericGenerator(name = "foreign", strategy = "foreign", parameters = { @Parameter(name = "property", value = "shopTab") })
    @Column(name = "SHOP_ID", unique = true, nullable = false, insertable = true, updatable = true, precision = 10, scale = 0)
    public Long getShopId() {
    return this.shopId;
    } public void setShopId(Long shopId) {
    this.shopId = shopId;
    } @OneToOne(cascade = {}, fetch = FetchType.LAZY, mappedBy="shopLevelTab")
    public ShopTab getShopTab() {
    return this.shopTab;
    } public void setShopTab(ShopTab shopTab) {
    this.shopTab = shopTab;
    }
    @OneToOne(cascade={CascadeType.ALL}, fetch=FetchType.LAZY, mappedBy="shopTab")
    @PrimaryKeyJoinColumn
    public ShopExTab getShopExTab() {
    return shopExTab;
    } public void setShopExTab(ShopExTab shopExTab) {
    this.shopExTab = shopExTab;
    }
    }
    public class ShopExTab implements java.io.Serializable {
           private ShopLevelTab shopLevelTab;
           @Id
        @GeneratedValue(generator = "foreign")   
        @GenericGenerator(name = "foreign", strategy = "foreign", parameters = { @Parameter(name = "property", value = "shopLevelTab") })
    @Column(name = "SHOP_ID", unique = true, nullable = false, insertable = true, updatable = true, precision = 10, scale = 0)
    public Long getShopId() {
    return this.shopId;
    }
    @OneToOne(cascade = {}, fetch = FetchType.LAZY, mappedBy="shopExTab")
    public ShopLevelTab getShopLevelTab() {
    return this.shopLevelTab;
    }
    }我这样配编译能通过,可启动服务的时候抛异常了
      

  8.   

    异常信息是:
    Caused by: org.hibernate.AnnotationException: Unknown mappedBy in: com.ffcs.ivr.entity.ShopExTab.shopLevelTab, referenced property unknown: com.ffcs.ivr.entity.ShopLevelTab.shopExTab
      

  9.   

    没看见现场,不太好分析,来段样例吧@Entity@Table(name = "customer")public class CustomerEO implements java.io.Serializable {  
    private AddressEO address;          @OneToOne(cascade = { CascadeType.ALL })         @PrimaryKeyJoinColumn         public AddressEO getAddress() {                   return address;         }          public void setAddress(AddressEO address) {                   this.address = address;         } 若AddressEO与CustomerEO双向关联,则应该修改AddressEO的代码如下:@Entity@Table(name = "address")public class AddressEO implements java.io.Serializable {                  ……         private CustomerEO customer;          @OneToOne         @PrimaryKeyJoinColumn         public CustomerEO getCustomer() {                   return customer;         }          public void setCustomer(CustomerEO customer) {                   this.customer = customer;         } }
      

  10.   

    大哥,能加下QQ或MSN吗?也不知道是不是因为我这有三层继承的原因,一直抛异常