Reputation: 1343
I am using Sprind JPA, Spring 3.1.2(in future 3.2.3), Hibernate 4.1 final. I am new to Sprind Data JPA. I have tow Table Release_date_type and Cache_media which entities are as follows :
ReleaseAirDate.java
@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; with getters and setters..
and CacheMedia as
@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; with setter and getters.
Now my repository interface is as follows :
public interface ReleaseDateTypeRepository extends CrudRepository<ReleaseDateType, Long>{ }
Now i want to write a method(Query) in ReleaseDateTypeRepository
interface which can get all the data from Release_Date_Type
table including appropriate media_description
from Table 'Cache_Media' based on media_id
of Release_date_type
table.
So my select (SQL)query looks like
SELECT * from Release_Date_Type r left join Cache_Media c on r.media_id=c.id
I don't know how to map entities. I tried so many thing but not luck. Any help is appreciated.
Upvotes: 1
Views: 5370
Reputation: 1285
Its not the answer for joining via Hibernate, but alternatively you can create a view with your join and map the view to your objects
Upvotes: 1