我想写一个类似的查询SELECT * FROM Release_date_type a LEFT JOIN cache_media b on a.id=b.id
。我是 Spring Data JPA 的新手。我不知道如何为 Join 查询编写实体。这是一个尝试:
@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();
}