• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

JPA question

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can I create a new entity in Namedquery like this -

@NamedQuery(name="productfordisplay",query=" SELECT NEW com.ssg.article.Product(p.name, p.id) FROM Product p where p.id=:id")

Is the above query valid. I want to return Product entity with only 2 attributes rather than all the attributes for display purpose (keep it lightweight).


Please clarify. I am in middle of design.

Thanks!
 
author and cow tipper
Posts: 5006
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would say 'no.'

When you bring back an object, you bring back all the properties for the object.

You can do just straight SQL, and in that case you just get back the database values in a multi-dimensional array.

Still, I might think this is far too low level for the SCEA exam. Am I wrong?

-Cameron McKenzie
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Reading from JPA specification:

A constructor may be used in the SELECT list to return one or more Java instances. The specified class
is not required to be an entity or to be mapped to the database. The constructor name must be fully qualified.



So I think it's OK.
 
reply
    Bookmark Topic Watch Topic
  • New Topic