This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Locating a bean without executing ejbCreate  RSS feed

 
Herbert Maosa
Ranch Hand
Posts: 289
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question could be trivial, but I would appreciate your help nevertheless.
Since a client obtains an instance of a bean by executing the ejbCreate, throught the available Create methods, I am wondering what I would do if I just wanted to access a database without inserting rows in it. For example a database that is already populated by some sql script and I just want to execute queries in it. I understand obtaining an instance through the create methods, it means inserting row, for an entity bean.
Herbert.
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Herbert
We have two kind of interfaces for beans. Home and Remote. Now, in Home interface you would see finder methods like findByPrimaryKey and other finder methods that are customized.
These finder methods are the one you are looking for here. Create methods of Home interface would create new records in db and to lookup the existing records via some query you would use finder methods.
e.g. if we have ProductHome object with us we can do following,
// create two products with PK as Product1 and Product2
productHome.create("Product1","Description 1");
productHome.create("Product2","Description 2");
// at some other place you can just lookup the added products as
Product product = productHome.findByPrimaryKey("Product1");
System.out.println(product.getPrice());
....
...
// lookup another product
product = productHome.findByPrimaryKey("Prodduct2");
System.out.println(product.getPrice());
Hopefully this helps a little.
Maulin
 
Herbert Maosa
Ranch Hand
Posts: 289
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Maulin. I will try to do this and tell you how I fair. I am attemtping to access a MySql database, using an entity bean with bean managed persitence: And I have not figured out how to access my sql database yet. I am on Linux, but I guess I can not ask the linux specific question here. But I will report to you how I fair the find methods.
Cheers,
Herbert.
 
Sawyer Shillong
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
How to implement entity bean cache, I mean whether ejbFind method will access db each time for BMP? How about CMP? Thanks.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37242
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For CMP, the container deals with caching so you don't have to. For BMP, if you want a cache, I think you will have to write one.
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by shillong:
Hi,
How to implement entity bean cache, I mean whether ejbFind method will access db each time for BMP? How about CMP? Thanks.

For CMP, it is all vendor-specific. Caching is one of the selling points for an App Server.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!