9

我正在使用 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 变量上有这些注释。任何可以提供的帮助将不胜感激!

4

3 回答 3

8

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

于 2013-08-07T02:48:27.563 回答
7

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

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

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

于 2016-12-11T00:01:34.743 回答
0

尝试在您的持久性单元标签中添加如下:

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

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

  1. Java SE 8
  2. Maven 项目
  3. EclipseLink(本地不是应用程序服务器)
  4. 网豆
于 2020-05-06T20:50:30.963 回答