我想編寫一個查詢像Select * from A a left join B b on a.id=b.id
, 我是新來春數據JPA。 我不知道怎麼寫的聯接查詢實體。連接兩個表實體春數據JPA
@Entity
@Table(name = "Release_date_type")
public class ReleaseDateType {
@Id
@GeneratedValue(strategy=GenerationType.TABLE)
private Integer release_date_type_id;
@Column
private Integer sort_order;
@Column
private String description;
@Column
private String data_source_type;
@Column(nullable = true)
private Integer media_Id;
@Column
private String source_system;
@Column
private String update_Name;
@Column
private Date update_Date;
@Column
private String create_Name;
@Column
private Date create_Date;
@Column
private Integer version_Id;
@Column(nullable = true)
private Integer auto_Firm_Flag;
@Column(nullable = true)
private Integer auto_Firm_Months;
@Column(nullable = true)
private Integer auto_Firm_Days;
with getters and setters...
}
另一個實體是
@Entity
@Table(name = "Cache_Media")
public class CacheMedia{
@Id
@GeneratedValue(strategy=GenerationType.TABLE)
private Integer id;
@Column(name="code")
private String code;
@Column(name="POSITION")
private Integer position;
@Column(name="DESCRIPTION")
private String media_Description;
@Column(name="LOAD_DATE")
private Date loadDate; with the getter and setter ..}
我想寫一個crudRepository接口。 如
public interface ReleaseDateTypeRepository extends CrudRepository<ReleaseDateType, Long>{
@Query("Select * from A a left join B b on a.id=b.id")
public List<ReleaseDateType> FindAllWithDescriptionQuery();
}
你需要你的實體之間的關聯。不要存儲其他實體的ID。存儲引用到其它實體,並使用OneToOne,多對一,一對多和多對多asociations。你的JPA教程(或者Hibernate文檔)應該覆蓋這個。 –
嗨Nizet,感謝您的快速反應,你有哪些可以給我關於與實體相關聯的詳細信息的任何教程。 –
搜索OneToOne,一對多,多對一和多對多的http://docs.jboss.org/hibernate/orm/4.2/manual/en-US/html_single –