org.hibernate.annotationexception no identifier specified for entity
生活随笔
收集整理的這篇文章主要介紹了
org.hibernate.annotationexception no identifier specified for entity
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
解決:org.hibernate.annotationexception no identifier specified for entity
HibernateEJB? org.hibernate.annotationexception no identifier specified for entity因為數據庫的表必須要定義主鍵,此類沒有定義主鍵
復合主鍵:
表 1-17 @IdClass 屬性
屬性 必需 說明
value
要指定復合主鍵類,請將 value 設置為所需的 Class(請參閱 @AttributeOverride)。
示例 1-37 顯示了一個非嵌入的復合主鍵類。在該類中,字段 empName 和 birthDay 的名稱和類型必須對應于實體類中屬性的名稱和類型。示例 1-38 顯示了如何使用這個非嵌入的復合主鍵類(使用 @IdClass 批注)配置 EJB 3.0 實體。由于實體類字段 empName 和 birthDay 在主鍵中使用,因此還必須使用 @Id 批注對其進行批注。
示例 1-37 非嵌入的復合主鍵類
public class EmployeePK implements Serializable
{
private String empName;
private Date birthDay;
public EmployeePK()
??? {
??? }
public String getName()
??? {
return empName;
??? }
public void setName(String name)
??? {
empName = name;
??? }
public long getDateOfBirth()
??? {
return birthDay;
??? }
public void setDateOfBirth(Date date)
??? {
birthDay = date;
??? }
public int hashCode()
??? {
return (int) empName.hashCode();
??? }
public boolean equals(Object obj)
??? {
if (obj == this) return true;
if (!(obj instanceof EmployeePK)) return false;
if (obj == null) return false;
EmployeePK pk = (EmployeePK) obj;
return pk.birthDay == birthDay && pk.empName.equals(empName);
??? }
}
示例 1-38 @IdClass
@IdClass(EmployeePK.class)
@Entity
public class Employee
{
@Id String empName;
@Id Date birthDay;
...
}
轉載于:https://www.cnblogs.com/zhangkaijia/p/3232205.html
總結
以上是生活随笔為你收集整理的org.hibernate.annotationexception no identifier specified for entity的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 数组---进制转换(查表法)
- 下一篇: Java ME游戏开发中,碰撞检测算法在