• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding JPA Select Query

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have a JPQL as shown below .

The below query

will return all Magazine instances whose publisher field is set to a Company instance whose name is "Random House".


SELECT x FROM Magazine x WHERE x.name = 'Random House'

Assume that the Magazine Table has Name ,ID , Author columns .

I dont want to retrive all of them but only Name and ID fields .

Please tell me how can i do this ??
 
Leonardo Carreira
Ranch Hand
Posts: 494
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..

Assume that you just want to retrieve Id and Author..
and the query would be :

SELECT x.Id, x.Author FROM Magazine x WHERE x.name = 'Random House'

Hope it would help you..
Thanks..

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Thank you very much.
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, if you still would like to return a Magazine object with only those fields set, assuming you have a Magazine object with a constructor that accepts the required fields, you could do somewhat like this:



In certain cases you will need to use the whole fully qualified name of the class:



I hope that helps!
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It helped .

Thank you .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic