使用变形金刚时无法在课堂上找到字段的setter

时间:2015-02-06 04:38:17

标签: java mysql hibernate

在我的hibernate应用程序中,我有一个可嵌入的类,如下所示

@Embeddable
public class ClientUserId implements Serializable {

    @Column(name = "client_id")
    private Long clientId;
    @Column(name = "user_id")
    private Long userId;

    public ClientUserId() {
    }

    public Long getClientId() {
    return clientId;
}

public void setClientId(Long clientId) {
    this.clientId = clientId;
}

public Long getUserId() {
    return userId;
}

public void setUserId(Long userId) {
    this.userId = userId;
}
}

和我的POJO课程

public class ClientUser implements Serializable {

    @Id
    @Embedded
    private ClientUserId clientUserId;
    @Column(name = "user_name", nullable = false, unique = true, length = 32)
    private String userName;
    @Column(name = "first_name", length = 32)
    private String firstName;
    @Column(name = "last_name", length = 32)
    private String lastName;
    @Column(name = "email", length = 64)
    private String email;
    public ClientUser() {
    }

  public ClientUserId getClientUserId() {
    return clientUserId;
}

public void setClientUserId(ClientUserId clientUserId) {
    this.clientUserId = clientUserId;
}

public String getUserName() {
    return userName;
}

public void setUserName(String userName) {
    this.userName = userName;
}

public String getFirstName() {
    return firstName;
}

public void setFirstName(String firstName) {
    this.firstName = firstName;
}

public String getLastName() {
    return lastName;
}

public void setLastName(String lastName) {
    this.lastName = lastName;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}
}

我的SQL查询是

 session.createSQLQuery("SELECT  user_id as userId,email as email,first_name as firstName,last_name as lastName,user_name as userName FROM users").
addScalar("email", new StringType()).addScalar("firstName", new StringType()).addScalar("lastName", new StringType()).addScalar("userName", 
new StringType()).addScalar("userId", new LongType()).setResultTransformer(Transformers.aliasToBean(ClientUser.class)).list();

在我的sql查询中,我从表用户获取结果集(ClientUser表的结构与一个字段clientId除外)并转换为名为ClientUser的类。 由于ClientUserId是嵌入式的,我收到错误Could not find setter for userId on class 我该如何解决这个问题?

0 个答案:

没有答案