gpt4 book ai didi

Hibernate 抛出 org.hibernate.AnnotationException : No identifier specified for entity: com. .domain.idea.MAE_MFEView

转载 作者:行者123 更新时间:2023-12-03 04:12:22 25 4
gpt4 key购买 nike

为什么我会收到此异常?

package com.domain.idea;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.annotations.AccessType;

/**
* object model for the view [InvestmentReturn].[vMAE_MFE]
*/
@Entity
@Table(name="vMAE_MFE", schema="InvestmentReturn")
@AccessType("field")
public class MAE_MFEView
{
/**
* trade property is a SuggestdTradeRecommendation object
*/
@OneToOne(fetch = FetchType.LAZY , cascade = { CascadeType.PERSIST })
@JoinColumn(name = "suggestedTradeRecommendationID")
private SuggestedTradeRecommendation trade;

/**
* Most Adeverse Excursion value
*/
private int MAE;

public int getMAE()
{
return MAE;
}

/**
* Most Favorable Excursion value
*/
private int MFE;

public int getMFE()
{
return MFE;
}

/**
* @return trade property
* see #trade
*/
public SuggestedTradeRecommendation getTrade()
{
return trade;
}
}

更新:我已将代码更改为如下所示:

package com.domain.idea;

import javax.persistence.CascadeType;
import javax.persistence.FetchType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.annotations.AccessType;

/**
* object model for the view [InvestmentReturn].[vMAE_MFE]
*/
@Entity
@Table(name="vMAE_MFE", schema="InvestmentReturn")
@AccessType("field")
public class MAE_MFEView
{
/**
* trade property is a SuggestdTradeRecommendation object
*/
@Id
@OneToOne(fetch = FetchType.LAZY , cascade = { CascadeType.PERSIST })
@JoinColumn(name = "suggestedTradeRecommendationID")
private SuggestedTradeRecommendation trade;

/**
* Most Adeverse Excursion value
*/
private int MAE;

public int getMAE()
{
return MAE;
}

/**
* Most Favorable Excursion value
*/
private int MFE;

public int getMFE()
{
return MFE;
}

/**
* @return trade property
* see #trade
*/
public SuggestedTradeRecommendation getTrade()
{
return trade;
}
}

但现在我遇到了这个异常:

Caused by: org.hibernate.MappingException: Could not determine type for: com.domain.idea.SuggestedTradeRecommendation, at table: vMAE_MFE, for columns: [org.hibernate.mapping.Column(trade)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:292)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:276)
at org.hibernate.mapping.RootClass.validate(RootClass.java:216)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1135)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1320)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
... 145 more

最佳答案

您缺少用 @Id 注释的字段。每个@Entity 都需要一个@Id - 这是数据库中的主键。

如果您不希望实体保留在单独的表中,而是希望成为其他实体的一部分,则可以使用 @Embeddable 而不是 @Entity.

如果您只是想要一个数据传输对象来保存来自 hibernate 实体的一些数据,请不要在其上使用任何注释 - 保留一个简单的 pojo。

更新:关于 SQL View ,Hibernate 文档写道:

There is no difference between a view and a base table for a Hibernate mapping. This is transparent at the database level

关于Hibernate 抛出 org.hibernate.AnnotationException : No identifier specified for entity: com. .domain.idea.MAE_MFEView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4381290/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com