• 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:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Entity EJB Question...

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know this is a bad idea (and I should use normal JDBC for this) but if I wanted to get hold of all, say 10 records for a drop down box, from a DB without knowing the keys, how do I do it using entity EJB?
TIA
Dave
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You would need to write a finder method and call this from the home interface of your Entity Bean. An example of a finder method is findByPrimaryKey() which is required for all Entity Beans. You can also define other finder methods (all starting with findBy) that can return either a single Entity or a multiple Entities in the form of a Collection or Set.
 
Dave Hewitson
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...ok, I would need to do the sql myself then?
If you use CMP is it acceptable to have a method which you implement yourself?
 
Chris Mathews
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are using CMP (I am assuming EJB 2.0) then you could use EJB-QL to define your query.
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why would you even want to use an entity bean to read records in the first place? Can you not use straight JDBC, or even better DAO and just hit the DB?
 
Dave Hewitson
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the replies, I know I should use straight JDBC for this, but wanted to know if there was an alternative.
Dave
 
reply
    Bookmark Topic Watch Topic
  • New Topic