我有簡單的實體,如:使用Hibernate查詢與實體領域
@Entity
public class University implements Serializable {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@Column
String name;
@Column
String address;
@Column
Student student;
}
和實體學生:
@Entity
public class Student implements Serializable {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@Column
String Firstname;
@Column
String LastName;
@Column
StudentStatus status;
}
我可以創造@JoinFormula或類似的東西來創建查詢,這將從學生實體到大學實體的學生?
我想類似的東西:
@JoinFormula("SELECT l FROM Student l where l.id = 1")
Student student;
,但它不工作。 我可以創建查詢來選擇一些學生嗎?
已更新: @JoinFormula從未打過電話。
根本不是。我想創建查詢,以採取學生的一些參數,所以我不想使用OneToMany註釋。列學生只是可變的。我不想使用OneToMany映射。 – 2013-04-25 11:18:34
你在這裏檢查:[Hibernate @JoinFormula](http://stackoverflow.com/questions/10980337/hibernate-joinformula) – 2013-04-25 11:19:28
是的,我試過了,但公式總是返回NULL。看起來這個公式從未被調用過。 – 2013-04-25 11:26:32