aspose file tools*
The moose likes Object Relational Mapping and the fly likes JPA trying to pass list to IN part of query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA trying to pass list to IN part of query" Watch "JPA trying to pass list to IN part of query" New topic
Author

JPA trying to pass list to IN part of query

john mattucci
Ranch Hand

Joined: Nov 03, 2000
Posts: 331
Im trying the following with no luck how would I go about passing a list as a parameter and then using it

List<Number> list =
em.createQuery("select number from Number number where number.phone in (:numberList)")
.setParameter("numberList", thisIsAList<Number> .getResultList();

When I change the "where number.phone" portion of the query to "where number" I get a object references an unsaved transient instance - save the transient instance before flushing: Number error

Thank you all for your time
[ July 16, 2008: Message edited by: john mattucci ]
Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 513

shouldn't we be using .setParameterList as opposed to .setParameter.


If you are not laughing at yourself, then you just didn't get the joke.
john mattucci
Ranch Hand

Joined: Nov 03, 2000
Posts: 331
There is no such method in javax.persistence.Query. If I change the list to contain Strings and the leave the "where number.phone" portion as is it works. What I'm trying to do is check if the numbers already exist in the DB. My question now is can I attempt what I'm trying to do i.e. use the Number object to see if the data is the DB or is it trying to tell me that I cannot do that unless that data is first present in the DB?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

Originally posted by john mattucci:
There is no such method in javax.persistence.Query. If I change the list to contain Strings and the leave the "where number.phone" portion as is it works. What I'm trying to do is check if the numbers already exist in the DB. My question now is can I attempt what I'm trying to do i.e. use the Number object to see if the data is the DB or is it trying to tell me that I cannot do that unless that data is first present in the DB?


I guess you can think of it this way, if you just use Number in the Where, how is that going to be translated to an SQL query to pass to the database. Include all the fields of the object in the where? Does sound very effective.

In Hibernate, not JPA there is the Criteria object, where you can use an Object with some data filled as an example to create a where clause with just the fields that have values.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JPA trying to pass list to IN part of query