我正在开发一个maven JDO项目,但是当我尝试在两个表之间建立关系时,我收到此错误(user_login,user_role)
User_Login:user_id(主键),user_name,user_password,user_role_id
User_Role:id(主键),角色
user_role_id与user_role表的ID相同
User.java:
@PersistenceCapable(table = "user_login")
public class User {
@PrimaryKey
@Column(name="user_id")
private Integer userId=0;
@Column(name="user_profile_name")
private String userProfileName=null;
@Column(name="user_email")
private String userEmail=null;
@Column(name="user_contact")
private String userContact=null;
@Column(name="user_name")
private String userName=null;
@Column(name="user_password")
private String userPassword=null;
@ManyToOne
@Column(name="user_role_id")
private Integer userRoleId=0;
Role.java:
@PersistenceCapable(table = "user_role")
public class Role {
@PrimaryKey
@Column(name="id")
private Integer id=0;
@Column(name="role")
private String role=null;
@OneToMany
private User userInfo=null;
DAOImpol:
public List<Role> getUser(String username, String userpassword) {
PersistenceManager pm = this.pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
JDOPersistenceManager jdopm = (JDOPersistenceManager)pm;
try {
// Start the transaction
tx.begin();
TypesafeQuery<User> tq = jdopm.newTypesafeQuery(User.class);
//QUser user = QUser.candidate();
QRole role = QRole.candidate();
QUser userInfo=role.userInfo;
List<Role> result = tq.filter(userInfo.userName.eq(username).and(userInfo.userPassword.eq(userpassword))).executeList();
//result = tq.executeResultList(true, user.userId);
if(result.size()>0){
log.info(">>>>>00000000"+" "+result.get(0).getUser().getUserEmail());
log.info(">>>>>11111111"+" "+result.get(0).getRoleId()+" "+result.get(0).getRole());
}else{
log.info("<<<<<<<=====000000");
}
// Commit the transaction, flushing the object to the datastore
tx.commit();
return result;
}
finally {
if (tx.isActive())
{
// Error occurred so rollback the transaction
tx.rollback();
}
pm.close();
}
我收到此错误:
javax.jdo.JDOUserException: Variable 'this.userInfo' is unbound and
cannot be determined (is it a misspelled field name? or is not intended
to be a variable?)
NestedThrowables:
org.datanucleus.exceptions.NucleusUserException: Variable
'this.userInfo' is unbound and cannot be determined (is it a
misspelled
field name? or is not intended to be a variable?)
答案 0 :(得分:0)
如果您使用progaurd并且progaurd重命名您的私人字段,我发现您将从JDO收到此错误。在progaurd配置中添加-keep以保持包含Persistence Capable类的包将修复它。
例如,如果将所有Persistence Capable类保留在com.example.server.orm包中,则将其添加到progaurd.conf
-keep class com.example.server.orm.** {*;}