类UserMSTR:
package com.java.spring.data.domain;
import java.io.Serializable;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import org.springframework.data.jpa.domain.AbstractPersistable;
@Entity
public class UserMSTR extends AbstractPersistable<Long> implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue()
private long userID;
private String userName;
private String password;
@OneToMany(mappedBy = "UserMSTR")
private Set<UserAttribute> userAttribute;
public long getUserID() {
return userID;
}
public void setUserID(long userID) {
this.userID = userID;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Set<UserAttribute> getUserAttribute() {
return userAttribute;
}
public void setUserAttribute(Set<UserAttribute> userAttribute) {
this.userAttribute = userAttribute;
}
}
类UserAttribute:
package com.java.spring.data.domain;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.springframework.data.jpa.domain.AbstractPersistable;
@Entity
public class UserAttribute extends AbstractPersistable<Long> implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private String attrName;
private String attrValue;
/* @GenericGenerator(name = "generator", strategy = "foreign",
parameters = @Parameter(name = "property", value = "USERMSTR"))
@Id
@GeneratedValue(generator = "generator")
private String userID;*/
@ManyToOne()
@JoinColumn(name="userID")
private UserMSTR userMstr;
public String getAttrName() {
return attrName;
}
public void setAttrName(String attrName) {
this.attrName = attrName;
}
public String getAttrValue() {
return attrValue;
}
public void setAttrValue(String attrValue) {
this.attrValue = attrValue;
}
/*public String getUserID() {
return userID;
}
public void setUserID(String userID) {
this.userID = userID;
}*/
public UserMSTR getUserMstr() {
return userMstr;
}
public void setUserMstr(UserMSTR userMstr) {
this.userMstr = userMstr;
}
/*public UserAttribute(String attrName, String attrValue, String userID, UserMSTR userMstr) {
super();
this.attrName = attrName;
this.attrValue = attrValue;
this.userID = userID;
this.userMstr = userMstr;
}*/
public UserAttribute(){
}
}
错误:
由以下原因引起:org.hibernate.AnnotationException:从com.java.spring.data.domain.UserAttribute引用com.java.spring.data.domain.UserMSTR的外键具有错误的列数。应该是2
最佳答案
@OneToMany(mappedBy = "UserMSTR")
确保存在这样的Reference变量:
UserMSTR UserMSTR;
类中的UserAttribute
(因为您在mappedBy = "UserMSTR"
类中提到了UserMSTR
)。可能是您的引用变量名称与您在
mappedBy
中使用的引用变量名称不同。希望这会工作!!!