由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - JPA Criteria API select question
相关主题
请教一个hinbernate mapping的问题,谢谢问问java认证
讨论spring这么多,还没有说到点子上的。问个JPA的问题
grammy, are you still working on the game projectSearch Results Navigation
做J2EE程序开发市场行情如何?Criticism of Java Persistence Frameworks
急问hibernater queryHow to specify indexes in JPA?
这个闭包怎么写?spring transaction的问题
缺乏经验的朋友请进hibernate和ejb3
问一个Many to Many的设计问题How to create empty tables in JPA/Hierbnate
相关话题的讨论汇总
话题: accounts话题: projects话题: join话题: account话题: long
进入Java版参与讨论
1 (共1页)
r*****s
发帖数: 985
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.
t*******e
发帖数: 684
2
You have to choose between a join or a subselect. Bear in mind that JPA
can't go beyond the capacity of SQL.
r*****s
发帖数: 985
3
you didn't get my point:
I just want the account_id which is available
in the projects table already. I don't need
other accounts columns. that's why I don't
want another join.

【在 t*******e 的大作中提到】
: You have to choose between a join or a subselect. Bear in mind that JPA
: can't go beyond the capacity of SQL.

t*******e
发帖数: 684
4
Ok, I was fooled by the naming of "Accounts".
One-to-many may be mapped through a join table instead of a FK, that implies
a JOIN is always needed. To avoid a join, the FK needs to be mapped
explicitly like an attribute in the Projects in addition to the many-to-one
relationship, like this.
public class Projects {
private Long id;
private Accounts accounts;
private Long accountsId;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "Account_ID")
public Accounts getAccounts() {
return this.accounts;
}
@Column(name = "Account_ID", nullable = false, precision = 22, insertable
= false, updatable = false)
public Long getAccountsId() {
return accountsId;
}
}
r*****s
发帖数: 985
5
thanks,
i've been aware of this method , as mapping "another account_id directly",
i am asking any simpler way with metamodel?
another related question, on the other way, is, if there is
no FK, how can i do join?
for example, if account_id has no FK to Accounts table,
how to write the join?
It doesn't seem to make any sense at the beginning, however, in reality, it
makes sense in some bug fixing case.

implies
one

【在 t*******e 的大作中提到】
: Ok, I was fooled by the naming of "Accounts".
: One-to-many may be mapped through a join table instead of a FK, that implies
: a JOIN is always needed. To avoid a join, the FK needs to be mapped
: explicitly like an attribute in the Projects in addition to the many-to-one
: relationship, like this.
: public class Projects {
: private Long id;
: private Accounts accounts;
: private Long accountsId;
: @ManyToOne(fetch = FetchType.LAZY)

t*******e
发帖数: 684
6
If I understand you correctly, what you refer to is theta-join. Here is a
SQL example.
SELECT *
FROM employee
JOIN department
ON employee.DepartmentID = department.DepartmentID; 
In JPQL,
SELECT *
FROM employee e, department d
where e.DepartmentID = d.DepartmentID;

it

【在 r*****s 的大作中提到】
: thanks,
: i've been aware of this method , as mapping "another account_id directly",
: i am asking any simpler way with metamodel?
: another related question, on the other way, is, if there is
: no FK, how can i do join?
: for example, if account_id has no FK to Accounts table,
: how to write the join?
: It doesn't seem to make any sense at the beginning, however, in reality, it
: makes sense in some bug fixing case.
:

r*****s
发帖数: 985
7
SQL/HQL/JPQL我都知道啊,
就是用Criteria/Metamodel咋写啊?
很大的一个Query都是Criteria写的。

【在 t*******e 的大作中提到】
: If I understand you correctly, what you refer to is theta-join. Here is a
: SQL example.
: SELECT *
: FROM employee
: JOIN department
: ON employee.DepartmentID = department.DepartmentID; 
: In JPQL,
: SELECT *
: FROM employee e, department d
: where e.DepartmentID = d.DepartmentID;

1 (共1页)
进入Java版参与讨论
相关主题
How to create empty tables in JPA/Hierbnate急问hibernater query
问个Spring Framework的数据库设置的问题这个闭包怎么写?
JSF, Wicket, and Vaadin缺乏经验的朋友请进
这么多的JSF Ajax Component Libraries问一个Many to Many的设计问题
请教一个hinbernate mapping的问题,谢谢问问java认证
讨论spring这么多,还没有说到点子上的。问个JPA的问题
grammy, are you still working on the game projectSearch Results Navigation
做J2EE程序开发市场行情如何?Criticism of Java Persistence Frameworks
相关话题的讨论汇总
话题: accounts话题: projects话题: join话题: account话题: long