Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

BMP Entity EJBs and create()

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was reading jGuru's page on What is a BMP bean?. I think it's finally clicked for how I need to use Entity EJBs with the proprietary API that I unfortunately have to work with.
One remaining question that I have from that jGuru page is what happens with the create() method in the Home Interface.
I know that in a CMP, the container writes the code needed to create a new entity with a primary key. However, since I am using BMP and need to have my own data access logic handle this, how would I accomplish it? The jGuru article leaves that detail out.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
suppose it is ur callback method for creating customer instances.
But dont forget to create connection first. I hope it will be a good example for u. This time i am in hurry if u still find any problem post it here i will reply (inshaallah).
public String ejbCreate(String id, String name,
String address, String telephone){
try{
System.out.println("in ejbCreate()");
addCustomer(id, name, address, telephone);
}
catch(Exception e){
throw new EJBException(e.getMessage());
}
this.id = id;
this.name = name;
this.address = address;
this.telephone = telephone;
return id;
}
////////////////////DATABASE/////////////////////
public void addCustomer(String id, String name,
String address, String telephone)
throws SQLException{
String query = "INSERT INTO CUSTOMER VALUES(?, ?, ?, ?)";
PreparedStatement ps = connection.prepareStatement(query);
ps.setString(1, id);
ps.setString(2, name);
ps.setString(3, address);
ps.setString(4, telephone);
ps.executeUpdate();
ps.close();
}
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The process which runs at the background on calling create() method of home interface are as follows:
In the case of entity beans already bean instances would be created and will be in the pooled state.
When u invoke the create() method of the home interface,an EJBObject would be generated by the EJBServer and an instance is taken from the pool and assigned to this EJBObject.Then that instance's ejbCreate() would be called wherein u write ur own code to insert entries to DataBase.
Finally it returns a primary key to the container and the primary key is embedded in the ejbObject and this object(Remote stub) is return to the client thru which client can access the business methods of the bean.
Cheers
Geeta
 
Michael Brewer
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Shoaib Khanzada:
public String ejbCreate(String id, String name,
String address, String telephone){
try{
<snip>
}
}


Thanks, Shoaib. Would I put that code in the implementation bean (CustomerBean.java) or in the home interface (CustomerHome.java)?
I assume it would go in the bean class.
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael,
Perhaps this thread is relevant to you?
https://coderanch.com/t/311386/EJB-JEE/java/Some-basic-questions
Hope it helps.
Good Luck,
Avi.
 
Shoaib Khanzada
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes it is the code for CustomerBean class. How u expect that it will come in CustomerHome dont u know the convention. Here i am giving u the convention always make beans to follow these conventions it will help u to manage ur code.
Home Interface = CustomerHome (Bean name follwed by Home)
Remote Interface = Customer (Just bean name)
Bean Class = CustomerBean (Bean name followed by Bean)
Client = CustomerClient (Bean name followed by Client)
I hope now u will get the idea so that is code and is implemented by ur bean class and this time the bean class is 'CustomerBean'
thanks
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic