帮忙看下,高分结贴,急急急。。。。
用SSH作的系统,有张表用的是复合主键,帮忙看下在.hbm.xml配置文件中这样配置复合主键对吗?
<hibernate-mapping>
<class name="com.tzl.entity.Debit" table="debit" catalog="PARKINFO-PLATFORM">
<composite-id name="id" class="com.tzl.entity.DebitId">
<key-property name="devId" type="java.lang.Integer">
<column name="dev_id" />
</key-property>
<key-property name="outTime" type="java.sql.Timestamp">
<column name="out_time" length="19" />
</key-property>
</composite-id>
这个是实体类,主键单独是一个类,如下:
public class Debit implements java.io.Serializable {
private DebitId id;
private Integer cardUid;
private Float cash;
private Float paidIn;
private Float balance;
private Timestamp inTime;
private Integer cardStatus;
private Integer tag;
private Integer devIdIncar;
public Debit() {
}
public Debit(DebitId id) {
this.id = id;
}
public Debit(DebitId id, Integer cardUid, Float cash, Float paidIn,
Float balance, Timestamp inTime, Integer cardStatus, Integer tag,
Integer devIdIncar) {
this.id = id;
this.cardUid = cardUid;
this.cash = cash;
this.paidIn = paidIn;
this.balance = balance;
this.inTime = inTime;
this.cardStatus = cardStatus;
this.tag = tag;
this.devIdIncar = devIdIncar;
}
public DebitId getId() {
return this.id;
}
public void setId(DebitId id) {
this.id = id;
}
public Integer getCardUid() {
return this.cardUid;
}
public void setCardUid(Integer cardUid) {
this.cardUid = cardUid;
}
public Float getCash() {
return this.cash;
}
public void setCash(Float cash) {
this.cash = cash;
}
public Float getPaidIn() {
return this.paidIn;
}
public void setPaidIn(Float paidIn) {
this.paidIn = paidIn;
}
public Float getBalance() {
return this.balance;
}
public void setBalance(Float balance) {
this.balance = balance;
}
public Timestamp getInTime() {
return this.inTime;
}
public void setInTime(Timestamp inTime) {
this.inTime = inTime;
}
public Integer getCardStatus() {
return this.cardStatus;
}
public void setCardStatus(Integer cardStatus) {
this.cardStatus = cardStatus;
}
public Integer getTag() {
return this.tag;
}
public void setTag(Integer tag) {
this.tag = tag;
}
public Integer getDevIdIncar() {
return this.devIdIncar;
}
public void setDevIdIncar(Integer devIdIncar) {
this.devIdIncar = devIdIncar;
}
}
主键类:
public class DebitId implements java.io.Serializable {
private Integer devId;
private Timestamp outTime;
public DebitId() {
}
public DebitId(Integer devId, Timestamp outTime) {
this.devId = devId;
this.outTime = outTime;
}
public Integer getDevId() {
return this.devId;
}
public void setDevId(Integer devId) {
this.devId = devId;
}
public Timestamp getOutTime() {
return this.outTime;
}
public void setOutTime(Timestamp outTime) {
this.outTime = outTime;
}
} class
[解决办法]
我觉得还是不用复合主键的好。
[解决办法]
http://www.cnblogs.com/otomedaybreak/archive/2012/01/25/2329390.html
看看这个把。
[解决办法]
复合主键没有配置过。感觉你搞麻烦了。可不可以用代码控制下了。我觉得代码控制应该也能满足你要求。
[解决办法]
看你怎么配置的啊,如果用注解有没有用 @EmbeddedId和@Embeddable