java Hibernate 映射异常 - 无法确定以下类型的类型:

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26416881/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 09:53:42  来源:igfitidea点击:

Hibernate mapping exception - Could not determine type for:

javahibernatejpaormhibernate-mapping

提问by Fabio K

Im trying to configure my entities but hibernate throws the following exception:

我正在尝试配置我的实体,但休眠会引发以下异常:

org.hibernate.MappingException: Could not determine type for: com.sd.entity.SDUserProductAcess,   at table: SDUser, for columns: [org.hibernate.mapping.Column(productAccess)]
[PersistEngine] Failed to initialize persistence engine!java.lang.NullPointerException

These are my Entities:

这些是我的实体:

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class SDObject
{

@Id
@GeneratedValue
private long sdId;
private String sdType;

public long getSdId()
{
    return sdId;
}

public void setSdId(long sdId)
{
    this.sdId = sdId;
}

public String getSdType()
{
    return sdType;
}

public void setSdType(String sdType)
{
    this.sdType = sdType;
}
}

The next one:

下一个:

@Entity
public class SDUser extends SDObject
{

@Column(unique = true)
private String code;
private String password;
private SDUserProductAcess productAccess;

public String getCode()
{
    return code;
}

public void setCode(String code)
{
    this.code = code;
}

public String getPassword()
{
    return password;
}

public void setPassword(String password)
{
    this.password = password;
}

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
public SDUserProductAcess getProductAccess()
{
    return productAccess;
}

public void setProductAccess(SDUserProductAcess productAccess)
{
    this.productAccess = productAccess;
}

The last one:

最后一个:

@Entity
public class SDUserProductAcess extends SDObject
{

private boolean adm;

public boolean isAdm()
{
    return adm;
}

public void setAdm(boolean adm)
{
    this.adm = adm;
}
}

Hibernate can't determine the type for column productAccess, located in SDUser entity. I'm new to Hibernate and I can't figure out what is happening.

Hibernate 无法确定位于 SDUser 实体中的列 productAccess 的类型。我是 Hibernate 的新手,我无法弄清楚发生了什么。

Should I provide some kind of ID?

我应该提供某种身明吗?

Thanks!!

谢谢!!

回答by Vlad Mihalcea

In SDUseryou need to add the association info on the SDUserAccess:

SDUser您需要添加的关联信息SDUserAccess

@ManyToOne
@JoinColumn(name = "sdId")
private SDUserProductAcess productAccess;