• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help Me Demistify this  RSS feed

 
Herbert Maosa
Ranch Hand
Posts: 289
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have struggle for so long to try and figure this for myself but now my brains have stopped,someone help me.
I am simply trying to get an Entity Bean to create database rows. When I use a session bean, the bean inserts the row without a problem. When I convert the bean to an Entity Bean, I get no errors, but nothing gets inserted into the database. Can someone try to explain to me what is going on here? All the database call remain unchanged, all I am doing is changing the Enterprise Bean type to Entity and implementing the necessary methods.
I would appreciate your help on this, it's got my head spinning.

Herbert.
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Herbert,
You need to specify the App Server that you are using. Did you make the necessary changes to the vendor specific CMP persistence descriptor file?...Did you also check the transaction attributes for the Entity bean?...
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And another piece of information -- are you converting this Session bean to a BMP or CMP bean? They are QUITE different...
Kyle
 
Herbert Maosa
Ranch Hand
Posts: 289
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. I am using the Sun Application Server that comes bundled with the J2EE sdk.
2. I am converting it to a BMP Entity Bean.
3. I have not defined or configured any transaction, I don't even know if I need to. All I am trying to do is create records in a database. I can easily create the records if the bean is a session bean.
Please Help.
Herbert.
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show us your code in ejbCreate and ejbStore...
Kyle
 
Herbert Maosa
Ranch Hand
Posts: 289
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Herewith my code for the ejbCreate and ejbStore. Please help me, I am really stuck here.

The method createUser(String firstName, String lastName, String userName, String password ) opens a database connection and executes an SQL insert statement to insert those fields in the database.

The method storeCustomer() invokes an SQL update statement to update the fields firstName, lastName, userName, password from the underlying table.
I have only included the parts of the code that you asked for and I hope you can help me make sense of what is going on.
Thanks,
Herbert.
 
Herbert Maosa
Ranch Hand
Posts: 289
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I enable ejbLoad() and ejbStore() I get humangous stack trace. If I make these empty, the errors disappear but nothing happends on the database.
Please please, Help.
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would make sense that nothing happens if you disable or delete these methods -- that's where all the work happens?
Can you show us your storeCustomer() and createCustomer() methods?
Kyle
 
Herbert Maosa
Ranch Hand
Posts: 289
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Herewith the storeCustomer() and the createCustomer() methods




Please Help,
Herbert.
 
Herbert Maosa
Ranch Hand
Posts: 289
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Herbert Maosa:
Herewith my code for the ejbCreate and ejbStore. Please help me, I am really stuck here.

The method createUser(String customerID, String firstName, String lastName, String userName, String password ) opens a database connection and executes an SQL insert statement to insert those fields in the database.

The method storeCustomer() invokes an SQL update statement to update the fields firstName, lastName, userName, password from the underlying table.
I have only included the parts of the code that you asked for and I hope you can help me make sense of what is going on.
Thanks,
Herbert.
 
Herbert Maosa
Ranch Hand
Posts: 289
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It appears to me like the problem has to do with transactions ( I am not sure though ).
In the stack trace, the nested exception is javax.transaction.Rollback Exception
I am really lost. I thought it should be straightforward. The exact same logic works for session bean.
Herbert.
 
raphael Bereh
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BMP is not supported for Entity beans in J2EE 1.3 if this is your platform.
You have to use CMP ! It is said in the J2EE spec. !
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by raphael Bereh:
BMP is not supported for Entity beans in J2EE 1.3 if this is your platform.
You have to use CMP ! It is said in the J2EE spec. !

That's just flat-out wrong. You do not understand the EJB spec. BMP is perfectly allowable in J2EE 1.3 and 1.4. Read the darned spec before you post crud like this.
Kyle
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Herbert,
Here's what worries me. In your code you seem to be holding the connection as an instance variable of your BMP. That's a very bad idea. The connections should be obtained, used and released within the same method. Holding the connection across multiple EJB lifecycle methods could easily confuse the container, and might be causing your problem.
Also, I don't know how you're obtaining the connection, which may also be causing problems. Could you post the code of the makeConnection() method also?
Kyle
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more thing -- you're eating your exceptions! Have you considered that you might be getting a SQL Exception, which is causing the rollback? Print out the exception text to the Standard output (using System.out.println) and see if you're not trying to do something like inserting values that have already been inserted...
Kyle
 
raphael Bereh
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kyle,
I said BMP for Entity beans !
 
raphael Bereh
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ooops ,
Kyle, I know in the spec (2.0) there is a whole chapter for BMP Entity Bean .
I have just complited the SCBCD exam, and all books, articles, I read say that BMP/BMT is not for Entity Beans in 2.0
I don't know what to think, please help.
 
Tha'er Zayed
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a good chance the PK does not get created for some reason.. EJB won't insert the row in this case, so maybe you need to look at that aspect..
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by raphael Bereh:
Ooops ,
Kyle, I know in the spec (2.0) there is a whole chapter for BMP Entity Bean .
I have just complited the SCBCD exam, and all books, articles, I read say that BMP/BMT is not for Entity Beans in 2.0
I don't know what to think, please help.

I think you might be misunderstanding the tone of the articles. They're de-emphasizing BMP, sure, because the capabilities of CMP have much improved in EJB 2.0. However, there are some cases where you still need BMP, and it is fully supported for those cases. Mostly that deals with non-relational datasources, or relational tables where the table model is completely different from the object model and you can't easily map from one to the other. But rest assured, it's still supported.
Kyle
 
raphael Bereh
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Kyle,
That clarifies things up in my mind.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!