有关员工拥有一个或多个电话的典型示例,请参阅此Wikibook部分。
对于你的特定示例,如果你想建立
one-to-one关系,则应更改ReleaseDateType模型中的下一个代码:
@Column(nullable = true) private Integer media_Id;
对于:
@oneToOne(fetch = FetchType.LAZY)@JoinColumn(name="CACHE_MEDIA_ID", nullable=true)private CacheMedia cacheMedia ;
在CacheMedia模型中,你需要添加:
@oneToOne(cascade=ALL, mappedBy="ReleaseDateType")private ReleaseDateType releaseDateType;
然后应在你的存储库中替换:
@Query("Select * from A a left join B b on a.id=b.id")public List<ReleaseDateType> FindAllWithDescriptionQuery();
通过:
//In this case a query annotation is not need since spring constructs the query from the method namepublic List<ReleaseDateType> findByCacheMedia_Id(Integer id);
或通过:
@Query("FROM ReleaseDateType AS rdt WHERe cm.rdt.cacheMedia.id = ?1") //This is using a named query methodpublic List<ReleaseDateType> FindAllWithDescriptionQuery(Integer id);
或者,如果你喜欢使用
@oneToManyand @ManyToOne关系,则应在
ReleaseDateType模型中更改下一个代码:
@Column(nullable = true) private Integer media_Id;
对于:
@oneToMany(cascade=ALL, mappedBy="ReleaseDateType")private List<CacheMedia> cacheMedias ;
在CacheMedia模型中,你需要添加:
@ManyToOne(fetch = FetchType.LAZY)@JoinColumn(name="RELEASE_DATE_TYPE_ID", nullable=true)private ReleaseDateType releaseDateType;
然后应在你的存储库中替换:
@Query("Select * from A a left join B b on a.id=b.id")public List<ReleaseDateType> FindAllWithDescriptionQuery();
通过:
//In this case a query annotation is not need since spring constructs the query from the method namepublic List<ReleaseDateType> findByCacheMedias_Id(Integer id);
或通过:
@Query("FROM ReleaseDateType AS rdt LEFT JOIN rdt.cacheMedias AS cm WHERe cm.id = ?1") //This is using a named query methodpublic List<ReleaseDateType> FindAllWithDescriptionQuery(Integer id);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)