File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Object Relational Mapping
how to write the jpql to query against the one to many table
Joined: Jun 20, 2007
Jul 31, 2011 01:39:22
I asked the question in my last post but not sure why no reply.
So I post it again as an standalone question.
I have 2 tables Customer and Contact. One customer can have multiple contacts.
So the relationship is one to many.
Part of Customer Entity:
@OneToMany(cascade = CascadeType.REFRESH, mappedBy="customer", fetch = FetchType.EAGER)
private Set<Contact> contacts;
Part of Contact Entity:
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "customer_ID")
private Customer customer;
@Column(name = "FIELD_NAME")
@Column(name = "FIELD_VALUE")
@Length(max = 100, message = "Maximum length allowed for user defined field is 100")
private String fieldValue;
Now I want to search out the customers based on the contact criterias.
For example, the criteria is fieldName='home number' and fieldValue='1234'
How to write such JPQL?
It could looks like,
select c from Customer c where c.contacts.fieldName='home number' and c.contacts.fieldValue='1234'
Author and ninkuma
Joined: Jan 10, 2002
Jul 31, 2011 01:42:02
Please do not post the same question more than once.
Asking smart questions
Books by Bear
I agree. Here's the link:
subject: how to write the jpql to query against the one to many table
complicate JSP tag : bodyContent
Problem when execute the JPQL with Map
Heap exception while loading complete table data from database
Serching for a surname in my collection
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014