Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Object Relational Mapping
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Ron McLeod
paul wheaton
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Himai Minh
Bartenders:
Forum:
Object Relational Mapping
Help with HQL
stanislav bashkirtsev
Ranch Hand
Posts: 75
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
1. I have Customer. It has many Accounts.
2. I have Payment, that has one Account.
Question: how can I fetch all payments where customer=?
The SQL is something like this:
SELECT payments.* FROM payments INNER JOIN accounts ON payments.account = accounts.id INNER JOIN customers ON accounts.customerId = customers.id WHERE customers.id = 1
What it will be look like in HQL?
Bhavesh Dak
Ranch Hand
Posts: 93
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Probable Solution,
Please ignore syntax related flaws.
Query query = "from Customer c where c.id = cid"; sqlQuery.setLong("cid", customer.getCustomerId()); List<Account> acctList = ((Account)query.list().get(0)).getAccounts(); Criteria crit = session.createCriteria(Payment.class); crit.add(Restrictions.in("account",acctList); List<Payment> paymentList = crit.list();
Cheers,
Bhavesh.
SCJP 6(83%), SCWCD 5.0(100%)
stanislav bashkirtsev
Ranch Hand
Posts: 75
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
There are two of "select"((( It's very bad for performance(
Bhavesh Dak
Ranch Hand
Posts: 93
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Yeah that is interesting,
I am also curious if we can achieve this in a single HQL.
SCJP 6(83%), SCWCD 5.0(100%)
stanislav bashkirtsev
Ranch Hand
Posts: 75
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Maybe the only way is to create bidirectional relationships...
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
HQL join syntax
Hibernate Inner Join with AND criteria
IN clause filtering on OneToMany/ManyToMany associations in JPQL
Hibernate Desing issue
Difference in HQL and Criteria
More...