One to many hibernate join if column names are different

你说的曾经没有我的故事 提交于 2019-12-05 07:35:52

You can specify reference column name

@JoinColumn(name="userlastname_fk", referencedColumnName="lastName")

see Hibernate documentation [1] section 2.2.3.2.1

[1] http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/

The name of the columns are irrelevant. The contract has an association to the vendor company, and an association to the customer company. And the company has an association with its time lines. So you don't need anything more. If you want the time lines of the vendor company of a contract, just call

contract.getVendorCompany().getTimeLines();

Side note: your bidirectional OneToMany between Company and CompanyTimeLine is wrong. It should be:

@OneToMany(fetch = FetchType.LAZY, orphanRemoval=true, mappedBy = "company")
@Cascade({org.hibernate.annotations.CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
@OrderBy(clause = "AS_OFF_DATE" )
private List<CompanyTimeline> companyTimeline = new ArrayList<CompanyTimeline>();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!