• Post Reply Bookmark Topic Watch Topic
  • New Topic

Entity EJB Question...  RSS feed

 
Dave Hewitson
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • 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
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • 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
  • 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: 2712
  • Mark post as helpful
  • send pies
  • 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.
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!