Hibernate mapping exception - Could not determine type for:

江枫思渺然 提交于 2019-12-18 04:44:35

问题


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.

Should I provide some kind of ID?

Thanks!!


回答1:


In SDUser you need to add the association info on the SDUserAccess:

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


来源:https://stackoverflow.com/questions/26416881/hibernate-mapping-exception-could-not-determine-type-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!