【问题标题】:Variable 'this.userInfo' is unbound and cannot be determined变量“this.userInfo”未绑定,无法确定
【发布时间】:2015-04-27 05:45:13
【问题描述】:

我正在开发一个 maven JDO 项目,但是当我尝试在两个表(user_login、user_role)之间建立关系时出现此错误

User_Login: user_id(primary key), user_name, user_password,user_role_id

User_Role:id(主键),角色

user_role_id 与 user_role 表的 id 相同

用户.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;

角色.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?)

【问题讨论】:

  • 我不是很了解JDO,但是你好像忘了说如何处理Role.userInfo。你不应该给OneToMany注解添加属性吗?
  • 您正在将 JPA 注释放入 JDO 项目中。这是完全错误的,我在你之前的问题中告诉过你;显然被忽略了。关系也不是“整数”。你读过任何 JDO 文档吗?
  • @Neil...我得到的资源很少。所以对我来说很难。我想映射这 2 个表。你能告诉我一些有用的链接吗?
  • 您使用的是 DataNucleus JDO,是吗?那么为什么不从他们的网站和文档开始呢? datanucleus.org/documentation/products/accessplatform.html
  • 我想使用 Querydsl JDO。而且我认为我的坚持声明是不正确的。我正在打开另一个问题。你可以检查一下吗?

标签: spring maven jdo pojo


【解决方案1】:

我发现如果您使用 progaurd 并且 progaurd 重命名您的私有字段,您会从 JDO 收到此错误。在 progaurd 配置中添加 -keep 以将包与您的 Persistence Capable 类一起保存将修复它。

例如,如果您将所有 Persistence Capable 类保存在 com.example.server.orm 包中,则将其添加到 progaurd.conf 中

-keep class com.example.server.orm.** {*;}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-10
    • 2016-06-14
    • 2018-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-11
    相关资源
    最近更新 更多