问题是这样的,三个表:
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,且主键相同
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,且主键相同
解决方案 »
- hibernate 一对一关联问题
- 会struts2和dhtmlx的高人请进来
- JAAS如何在cmd中设置两个config file
- 谁能给我一个级联保存与更新的完整例子
- 求救:有没有哪位大侠给我一份hibernate连接DB2的驱动!
- Webwork2 如何实现带参数跳转?
- 大家来谈谈Java体系和.net的区别吧!!!!
- 两个不同应用的ejb中有相同名字的cmp,发布会产生错误,怎么解决?
- 是这样的, 我用的是J2SDKEE的自己带的: deploytool来对EJB进行配置的
- 如何将long 类型的值转换成string类型
- 服务器端运用Response对象将xml文件发送到浏览器端提示下载的问题。
- API
请问这个在哪设呀?
是不是说要这样?才可以用@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;
}
@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;
}
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;
}
}我这样配编译能通过,可启动服务的时候抛异常了
Caused by: org.hibernate.AnnotationException: Unknown mappedBy in: com.ffcs.ivr.entity.ShopExTab.shopLevelTab, referenced property unknown: com.ffcs.ivr.entity.ShopLevelTab.shopExTab
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; } }