Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

JPA trying to pass list to IN part of query

 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 662
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shouldn't we be using .setParameterList as opposed to .setParameter.
 
john mattucci
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic