本文介绍了休眠异常:org.hibernate.AnnotationException:没有为实体指定标识符:com..domain.idea.MAE_MFEView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  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;
$ b / **
*视图[投资返回] vMAE_MFE,schema =InvestmentReturn)
@AccessType(field)
public class MAE_MFEView
{
/ **
* trade属性是SuggestdTradeRecommendation对象
* /
@OneToOne(fetch = FetchType.LAZY,cascade = {CascadeType.PERSIST})
@JoinColumn(name =suggestedTradeRecommendationID)
private SuggestedTradeRecommendation trade;

/ **
*绝对值偏移值
* /
private int MAE;

public int getMAE()
{
return MAE;
}

/ **
*最优惠的游览价值
* /
private int MFE;

public int getMFE()
{
return MFE;
}

/ **
* @return交易产权
*参见#trade
* /
public SuggestedTradeRecommendation getTrade()
{
回报交易;


更新:我将代码更改为这:

  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;
$ b / **
*视图[投资返回] vMAE_MFE,schema =InvestmentReturn)
@AccessType(field)
public class MAE_MFEView
{
/ **
* trade属性是SuggestdTradeRecommendation对象
* /
@Id
@OneToOne(fetch = FetchType.LAZY,cascade = {CascadeType.PERSIST})
@JoinColumn(name =suggestedTradeRecommendationID)
私人建议交易推荐交易;

/ **
*绝对值偏移值
* /
private int MAE;

public int getMAE()
{
return MAE;
}

/ **
*最优惠的游览价值
* /
private int MFE;

public int getMFE()
{
return MFE;
}

/ **
* @return交易产权
*参见#trade
* /
public SuggestedTradeRecommendation getTrade()
{
回报交易;


$ / code $ / pre

但现在我得到这个异常: p>

 原因:org.hibernate.MappingException:无法确定com.domain.idea.SuggestedTradeRecommendation的类型,其表格为:vMAE_MFE,对于列:[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 - 这是数据库中的主键。

如果您不希望您的实体被保存在单独的表中,而是成为其他实体的一部分,则可以使用 @可嵌入的代替 @Entity



如果您只需要一个数据传输对象更新:关于SQL视图,Hibernate文档写道:

更新:关于SQL视图,Hibernate文档编写如下:

p>


Why am I getting this exception?

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;
    }
}

Update: I've changed my code to look like this:

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;
    }
}

but now I'm getting this exception:

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
解决方案

You are missing a field annotated with @Id. Each @Entity needs an @Id - this is the primary key in the database.

If you don't want your entity to be persisted in a separate table, but rather be a part of other entities, you can use @Embeddable instead of @Entity.

If you want simply a data transfer object to hold some data from the hibernate entity, use no annotations on it whatsoever - leave it a simple pojo.

Update: In regards to SQL views, Hibernate docs write:

这篇关于休眠异常:org.hibernate.AnnotationException:没有为实体指定标识符:com..domain.idea.MAE_MFEView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 04:59