我想写一个查询,就像这样:SELECT * FROM Release_date_type a LEFT JOIN cache_media b on a.id=b.id
。我是Spring Data JPA的新手,不知道如何为连接查询编写实体。以下是我的尝试:
@Entity
@Table(name = "Release_date_type")
public class ReleaseDateType {
@Id
@GeneratedValue(strategy=GenerationType.TABLE)
private Integer release_date_type_id;
// ...
@Column(nullable = true)
private Integer media_Id;
// with getters and setters...
}
另一个实体是:
@Entity
@Table(name = "Cache_Media")
public class CacheMedia {
@Id
@GeneratedValue(strategy=GenerationType.TABLE)
private Integer id;
// ...
private Date loadDate; //with the getter and setter ..
}
我想编写一个CrudRepository
接口,例如:
public interface ReleaseDateTypeRepository extends CrudRepository<ReleaseDateType, Long>{
@Query("SELECT * FROM Release_date_type a LEFT JOIN cache_media b on a.id=b.id")
public List<ReleaseDateType> FindAllWithDescriptionQuery();
}