抽象模式类型未知

时间:2013-08-06 20:20:35

标签: jpa junit

我正在使用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变量上。我们将非常感谢您提供的任何帮助!

3 个答案:

答案 0 :(得分:7)

看看这个。它为同一案例http://java.dzone.com/tips/the-nasty-jpa-unknown-abstract

提出了一些建议

答案 1 :(得分:2)

如果您使用的是Java SE,则必须在persistence.xml中添加实体类的完全限定名称,如此

<persistence-unit ...>
    <class>your.custom.package.TestWebProfile</class>
</persistence-unit>

省略包装部件可能会导致您的错误。

答案 2 :(得分:0)

尝试按如下所示在持久性单元标记中添加

<exclude-unlisted-classes>false</exclude-unlisted-classes>

由于我的原因,尽管我使用完全限定的名称列出了持久性单元中的所有类,但是eclipseLink无法识别它们。一旦添加该行,它就可以工作。 我正在使用:

  1. Java SE 8
  2. Maven项目
  3. EclipseLink(本地不是应用程序服务器)
  4. Netbeans