JPA异常在尝试将BEAN持续到数据库时

发布于 2025-01-22 12:25:13 字数 5968 浏览 3 评论 0原文

JPA的新手并遇到了一个问题。 基本上,我正在创建此BEAN:

PurchaseOrderControlBean purchaseOrderControl = new PurchaseOrderControlBean();

并使用固定器将其填充数据。

在试图将数据持续到我的数据库时,我会得到以下例外:

java.lang.IllegalArgumentException: Object is not a known entity type.

我的实体:

@Entity
@Table(name = "IMS_PURCHASE_ORDER_CONTROL", schema = "IMS")
public class PurchaseOrderControlBean implements Serializable {
    
    /**
     * 
     */
    private static final long serialVersionUID = -5801211822984821162L;

    @Id
    @Column(name = "ID")
    private BigDecimal id;
    
    @Id
    @Column(name = "INSURED_ID")
    private BigDecimal insuredId;
    
    @Column(name = "PROCESS_TYPE")
    private BigDecimal processType;
    
    @Column(name = "PROCESS_KEY")
    private String processKey;
    
    @Column(name = "SUPER_ClLAIM_NUM")
    private BigDecimal superClaimNum;
    
    @Column(name = "PURCHASE_ORDER_NUM")
    private BigDecimal processOrderNum;
    
    @Column(name = "PURCHASE_ORDER_SERVICE_TYPE")
    private BigDecimal PurchaseOrderServiceType;
    
    @Id
    @Column(name = "CONTRACTOR_ID")
    private BigDecimal Contarctor_Id;
    
    @Column(name = "OPEN_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date openDate;
    
    @Column(name = "STATUS")
    private BigDecimal status;
    
    @Column(name = "EXECUTION_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date exccutionDate;
    
    @Column(name = "TOTAL_DURATION_DAYS")
    private BigDecimal totalDurationDays;
    
    @Column(name = "TOTAL_DELAY_DAYS")
    private BigDecimal totalDelayDays;
    
    @Id
    @Column(name = "UPDATE_USER_ID")
    private BigDecimal updateUserId;

    public BigDecimal getId() {
        return id;
    }

    public void setId(BigDecimal id) {
        this.id = id;
    }

    public BigDecimal getInsuredId() {
        return insuredId;
    }

    public void setInsuredId(BigDecimal bigDecimal) {
        this.insuredId = bigDecimal;
    }

    public BigDecimal getProcessType() {
        return processType;
    }

    public void setProcessType(BigDecimal processType) {
        this.processType = processType;
    }

    public String getProcessKey() {
        return processKey;
    }

    public void setProcessKey(String processKey) {
        this.processKey = processKey;
    }

    public BigDecimal getSuperClaimNum() {
        return superClaimNum;
    }

    public void setSuperClaimNum(BigDecimal superClaimNum) {
        this.superClaimNum = superClaimNum;
    }

    public BigDecimal getProcessOrderNum() {
        return processOrderNum;
    }

    public void setProcessOrderNum(BigDecimal processOrderNum) {
        this.processOrderNum = processOrderNum;
    }

    public BigDecimal getPurchaseOrderServiceType() {
        return PurchaseOrderServiceType;
    }

    public void setPurchaseOrderServiceType(BigDecimal purchaseOrderServiceType) {
        PurchaseOrderServiceType = purchaseOrderServiceType;
    }

    public BigDecimal getContarctor_Id() {
        return Contarctor_Id;
    }

    public void setContarctor_Id(BigDecimal contarctor_Id) {
        Contarctor_Id = contarctor_Id;
    }

    public Date getOpenDate() {
        return openDate;
    }

    public void setOpenDate(Date openDate) {
        this.openDate = openDate;
    }

    public BigDecimal getStatus() {
        return status;
    }

    public void setStatus(BigDecimal status) {
        this.status = status;
    }

    public Date getExccutionDate() {
        return exccutionDate;
    }

    public void setExccutionDate(Date exccutionDate) {
        this.exccutionDate = exccutionDate;
    }

    public BigDecimal getTotalDurationDays() {
        return totalDurationDays;
    }

    public void setTotalDurationDays(BigDecimal totalDurationDays) {
        this.totalDurationDays = totalDurationDays;
    }

    public BigDecimal getTotalDelayDays() {
        return totalDelayDays;
    }

    public void setTotalDelayDays(BigDecimal totalDelayDays) {
        this.totalDelayDays = totalDelayDays;
    }

    public BigDecimal getUpdateUserId() {
        return updateUserId;
    }

    public void setUpdateUserId(BigDecimal bigDecimal) {
        this.updateUserId = bigDecimal;
    }

持久方法:

public Object save(Object obj) throws TecnicalException {
        EntityManager entityManager = null;
        EntityTransaction updateTransaction = null;
        Object object = null;
        boolean success = false;
        try {
            entityManager = PersistenceUtil.getEntityManager(dbName);
            updateTransaction = entityManager.getTransaction();
            updateTransaction.begin();
            object = entityManager.merge(obj);
            success = true;
        } catch (PersistenceException e) {
            logger.error("Exception while trying to update object " + obj, e);
            ErrorLogUtil.writeErrorLog(Application.PERSISTANCE, "mng", null, "BaseDAO-Exception while trying to update object " + obj, "");
            throw new TecnicalException(e);
        } finally {
            if (success) {
                try {
                    updateTransaction.commit();
                } catch (Exception e) {
                    logger.error("Failed commit" + e);
                    throw new TecnicalException(e);

                }
            } else {
                if (updateTransaction != null && updateTransaction.isActive()) {
                    updateTransaction.rollback();
                }
            }
            if (entityManager != null) {
                entityManager.close();
                entityManager = null;
            }
        }
        return object;
    }

当调试异常时,

object = entityManager.merge(obj);

我似乎无法理解我在这里缺少的东西。 如果需要,我可以添加更多信息。

我在其他线程上看到了类似的问题,但是,这对我没有帮助。

谢谢

New to JPA and encountered an issue.
Basically I am creating this bean:

PurchaseOrderControlBean purchaseOrderControl = new PurchaseOrderControlBean();

and using setters in order to fill it with data.

While trying to persist data to my DB I get this exception:

java.lang.IllegalArgumentException: Object is not a known entity type.

My Entity:

@Entity
@Table(name = "IMS_PURCHASE_ORDER_CONTROL", schema = "IMS")
public class PurchaseOrderControlBean implements Serializable {
    
    /**
     * 
     */
    private static final long serialVersionUID = -5801211822984821162L;

    @Id
    @Column(name = "ID")
    private BigDecimal id;
    
    @Id
    @Column(name = "INSURED_ID")
    private BigDecimal insuredId;
    
    @Column(name = "PROCESS_TYPE")
    private BigDecimal processType;
    
    @Column(name = "PROCESS_KEY")
    private String processKey;
    
    @Column(name = "SUPER_ClLAIM_NUM")
    private BigDecimal superClaimNum;
    
    @Column(name = "PURCHASE_ORDER_NUM")
    private BigDecimal processOrderNum;
    
    @Column(name = "PURCHASE_ORDER_SERVICE_TYPE")
    private BigDecimal PurchaseOrderServiceType;
    
    @Id
    @Column(name = "CONTRACTOR_ID")
    private BigDecimal Contarctor_Id;
    
    @Column(name = "OPEN_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date openDate;
    
    @Column(name = "STATUS")
    private BigDecimal status;
    
    @Column(name = "EXECUTION_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date exccutionDate;
    
    @Column(name = "TOTAL_DURATION_DAYS")
    private BigDecimal totalDurationDays;
    
    @Column(name = "TOTAL_DELAY_DAYS")
    private BigDecimal totalDelayDays;
    
    @Id
    @Column(name = "UPDATE_USER_ID")
    private BigDecimal updateUserId;

    public BigDecimal getId() {
        return id;
    }

    public void setId(BigDecimal id) {
        this.id = id;
    }

    public BigDecimal getInsuredId() {
        return insuredId;
    }

    public void setInsuredId(BigDecimal bigDecimal) {
        this.insuredId = bigDecimal;
    }

    public BigDecimal getProcessType() {
        return processType;
    }

    public void setProcessType(BigDecimal processType) {
        this.processType = processType;
    }

    public String getProcessKey() {
        return processKey;
    }

    public void setProcessKey(String processKey) {
        this.processKey = processKey;
    }

    public BigDecimal getSuperClaimNum() {
        return superClaimNum;
    }

    public void setSuperClaimNum(BigDecimal superClaimNum) {
        this.superClaimNum = superClaimNum;
    }

    public BigDecimal getProcessOrderNum() {
        return processOrderNum;
    }

    public void setProcessOrderNum(BigDecimal processOrderNum) {
        this.processOrderNum = processOrderNum;
    }

    public BigDecimal getPurchaseOrderServiceType() {
        return PurchaseOrderServiceType;
    }

    public void setPurchaseOrderServiceType(BigDecimal purchaseOrderServiceType) {
        PurchaseOrderServiceType = purchaseOrderServiceType;
    }

    public BigDecimal getContarctor_Id() {
        return Contarctor_Id;
    }

    public void setContarctor_Id(BigDecimal contarctor_Id) {
        Contarctor_Id = contarctor_Id;
    }

    public Date getOpenDate() {
        return openDate;
    }

    public void setOpenDate(Date openDate) {
        this.openDate = openDate;
    }

    public BigDecimal getStatus() {
        return status;
    }

    public void setStatus(BigDecimal status) {
        this.status = status;
    }

    public Date getExccutionDate() {
        return exccutionDate;
    }

    public void setExccutionDate(Date exccutionDate) {
        this.exccutionDate = exccutionDate;
    }

    public BigDecimal getTotalDurationDays() {
        return totalDurationDays;
    }

    public void setTotalDurationDays(BigDecimal totalDurationDays) {
        this.totalDurationDays = totalDurationDays;
    }

    public BigDecimal getTotalDelayDays() {
        return totalDelayDays;
    }

    public void setTotalDelayDays(BigDecimal totalDelayDays) {
        this.totalDelayDays = totalDelayDays;
    }

    public BigDecimal getUpdateUserId() {
        return updateUserId;
    }

    public void setUpdateUserId(BigDecimal bigDecimal) {
        this.updateUserId = bigDecimal;
    }

Persist Method:

public Object save(Object obj) throws TecnicalException {
        EntityManager entityManager = null;
        EntityTransaction updateTransaction = null;
        Object object = null;
        boolean success = false;
        try {
            entityManager = PersistenceUtil.getEntityManager(dbName);
            updateTransaction = entityManager.getTransaction();
            updateTransaction.begin();
            object = entityManager.merge(obj);
            success = true;
        } catch (PersistenceException e) {
            logger.error("Exception while trying to update object " + obj, e);
            ErrorLogUtil.writeErrorLog(Application.PERSISTANCE, "mng", null, "BaseDAO-Exception while trying to update object " + obj, "");
            throw new TecnicalException(e);
        } finally {
            if (success) {
                try {
                    updateTransaction.commit();
                } catch (Exception e) {
                    logger.error("Failed commit" + e);
                    throw new TecnicalException(e);

                }
            } else {
                if (updateTransaction != null && updateTransaction.isActive()) {
                    updateTransaction.rollback();
                }
            }
            if (entityManager != null) {
                entityManager.close();
                entityManager = null;
            }
        }
        return object;
    }

When debugging the exception occurs on

object = entityManager.merge(obj);

I cannot seem to understand what I am missing here.
I could add any more information if needed.

I saw similar issues on other threads, however, it did not help me.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文