我正在使用 Spring 3.2.3、JPA 2.1、JUnit 4.11。我正在尝试运行 junit 测试,但我不断收到抽象模式类型未知错误。这是我的实体(截断空间,它有所有的 getter 和 setter):
@Entity
@Table(name = "WEB_PROFILES")
public class TestWebProfile implements Serializable {
private static final long serialVersionUID = 1L;
@Transient
private String forward;
@Column(name = "ACCESS_FLAG")
private String accessFlag;
@Temporal(TemporalType.DATE)
@Column(name = "ACCESS_FLAG_UPD_DATE")
private Date accessFlagUpdDate;
@Column(name = "ACCESS_RESET_INTERVAL")
private BigDecimal accessResetInterval;
@Column(name = "ACCOUNT_TYPE")
private String accountType;
@Column(name = "CREATED_BY")
private String createdBy;
@Column(name = "E_MAIL")
private String eMail;
@Column(name = "FAILED_LOGIN_ATTEMPTS")
private BigDecimal failedLoginAttempts;
@Column(name = "FIRST_NAME")
private String firstName;
@Temporal(TemporalType.DATE)
@Column(name = "FROI_ACCESS_APPROVE_DENY_DATE")
private Date froiAccessApproveDenyDate;
@Column(name = "FROI_ACCESS_APPROVED_FLAG")
private String froiAccessApprovedFlag;
@Column(name = "FROI_ACCESS_REQUESTED")
private String froiAccessRequested;
@Column(name = "FROI_APPROVED_BY")
private String froiApprovedBy;
@Temporal(TemporalType.DATE)
@Column(name = "FROI_CONFIRM_EMAIL_SENT_DATE")
private Date froiConfirmEmailSentDate;
@Temporal(TemporalType.DATE)
@Column(name = "FROI_LETTER_SENT_DATE")
private Date froiLetterSentDate;
@Column(name = "LAST_LOGON_ADDR")
private String lastLogonAddr;
@Temporal(TemporalType.DATE)
@Column(name = "LAST_LOGON_DATE")
private Date lastLogonDate;
@Column(name = "LAST_NAME")
private String lastName;
@Column(name = "LAST_UPDATED_BY")
private String lastUpdatedBy;
@Column(name = "LAST_UPDATED_BY_NAME")
private String lastUpdatedByName;
@Column(name = "LAST_UPDATED_BY_SU_ID")
private BigDecimal lastUpdatedBySuId;
@Temporal(TemporalType.DATE)
@Column(name = "MAIL_SENT_DATE")
private Date mailSentDate;
@Temporal(TemporalType.DATE)
@Column(name = "MAINT_DATE")
private Date maintDate;
@Temporal(TemporalType.DATE)
@Column(name = "NEW_PIN_REQ_DATE")
private Date newPinReqDate;
@Column(name = "PASSWORD")
private String password;
@Transient
private String newPassword;
@Temporal(TemporalType.DATE)
@Column(name = "PASSWORD_UPD_DATE")
private Date passwordUpdDate;
@Column(name = "PHONE")
private String phone;
@Column(name = "PIN")
private String pin;
@Column(name = "POLICY_NUM")
private BigDecimal policyNo;
@Column(name = "PROFILE_CLASS_CODE")
private String profileClassCode;
@Temporal(TemporalType.DATE)
@Column(name = "PROFILE_REQ_DATE")
private Date profileReqDate;
@Temporal(TemporalType.DATE)
@Column(name = "PROFILE_UPDATE_DATE")
private Date profileUpdateDate;
@Column(name = "REMOTE_ADDR")
private String remoteAddr;
@Column(name = "SESSIONID")
private String sessionid;
@Column(name = "SUBSCRIBER_FLAG")
private String subscriberFlag;
@Column(name = "USER_ID")
private BigDecimal userId;
@Id
@Column(name = "USER_NO")
private BigDecimal userNo;
@Column(name = "USERNAME")
private String username;
我的 JUnit 测试:
@Test
public void testGetWebProfileByUsername() {
TestWebProfile wp = sso.getWebProfile("MARLENE");
System.out.println("name :" + wp.getFirstName());
System.out.println("last name :" + wp.getLastName());
}
我的 DAO 实现:
@Override
public TestWebProfile getWebProfile(String username) {
String sqlString = "select w from TestWebProfile w where w.username =:username";
return (TestWebProfile) getEntityManager()
.createQuery(sqlString, TestWebProfile.class)
.setParameter("username", username).getSingleResult();
}
在谷歌搜索过去一个小时后,我发现唯一似乎有意义的罪魁祸首是没有 @Id 和 @Column 注释,但我在 userNo 变量上有这些注释。任何可以提供的帮助将不胜感激!