JPA Criteria API select question# Java - 爪哇娇娃
r*s
1 楼
for example,
public class Projects {
private Long id;
private Accounts accounts;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "Account_ID")
public Accounts getAccounts() {
return this.accounts;
}
}
if i just want to get the ID of the associated Accounts,
how can i avoid using join with the accounts table?
for example, now we may have to
Join accounts = projects.join(Projects_.accounts);
then
selectCols.add(accounts.get(Accounts_.id).alias("projectAcct"));
can i get it directly thru:
projects.get(Projects_.accounts.id) or similarly?
I know mapping another account_id directly is another way,
but checking whether there is any easy way to do this.
Thanks.
public class Projects {
private Long id;
private Accounts accounts;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "Account_ID")
public Accounts getAccounts() {
return this.accounts;
}
}
if i just want to get the ID of the associated Accounts,
how can i avoid using join with the accounts table?
for example, now we may have to
Join
then
selectCols.add(accounts.get(Accounts_.id).alias("projectAcct"));
can i get it directly thru:
projects.get(Projects_.accounts.id) or similarly?
I know mapping another account_id directly is another way,
but checking whether there is any easy way to do this.
Thanks.