This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes entity beans that don't persist? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "entity beans that don Watch "entity beans that don New topic
Author

entity beans that don't persist?

Simon Ingram
Ranch Hand

Joined: Nov 30, 2003
Posts: 173
Hi folks,

I have created a remote entity bean, which I access through a simple client which looks up the bean, gets the home, narrows it and passes some database fields to the ejbCreate. So, I create a few beans (rows in my database) and then access them with another simple client, which simply picks up a primary key from the command line and does a findByPrimaryKey(String key) and then prints out the fields of the bean. This works fine so long as I am in the same session where I created the beans. If I stop the server and restart, using one of the keys, I get an ObjectNotFoundException. I thought that these entity beans were supposed to be persistant! If the row exists in the database, then I should be able to get my bean back. Is there something I am forgetting? I am using the RI and Cloudscape database i.e. the defaults. Any ideas would be most welcome!

regards,
Simon
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Even though an entity survives a server crash, this does not mean that this is transparent to the client which may have to re-establish the home and component interfaces. In other words, the references which the client is holding are all re-establishable as long as the entity is still in the database.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Simon Ingram
Ranch Hand

Joined: Nov 30, 2003
Posts: 173
Hi Roger,

Yes, that's what I mean. When the entity beans are created, I assume the corresponding columns are created in the database. There was no server crash. I simply stopped the server and then restarted it. I was expecting that since the row exists in the database, my findByPrimaryKey method should send back a stub to the bean representing this row. I am most surprised to be loosing data.
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Are you saying that the client, having obtained the entity bean�s home interface, failed to locate a reference to an entity object by using its primary key?
Simon Ingram
Ranch Hand

Joined: Nov 30, 2003
Posts: 173
Yes, that's exactly what I am saying. I run the client and print at each step in the process. I get the home and when I execute findByPrimaryKey I get javax.ejb.ObjectNotFoundException: no database row for primary key. I am using the same key I used in my ejbCreate and this step did create a bean which I have previously interrogated. Everything gets lost when I stop and restart the server.
[ May 23, 2005: Message edited by: Simon Ingram ]
Herbert Maosa
Ranch Hand

Joined: May 03, 2000
Posts: 289
Are you able to directly connect to the database ( using an SQL interface ) and able to see the record that is assumed to have been created by the appplication?

Herbert..
Simon Ingram
Ranch Hand

Joined: Nov 30, 2003
Posts: 173
Hi Herbert,

I tried. The database is Cloudscape and there is an sql enquiry tool called the ij tool. It is featured in the J2EE documentation and suggests a link to IBM for more information. Unfortunately there is no information on the web site and the tool is old and bad. You cannot do strandard sql enquiries, for example


gives a syntax error! I did however manage to confirm that at least one of my records was in Cloudscape and I could enquire on it, but after a while this record just disappeared from the database!

I can enter more beans then enquire on them and then they too disappear. It is as though the beans are garbage collected and leave no trace in the database.
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
If there is no decent tool for Cloudscape, then dump it. Try another DB, maybe MySQL, and you will be able to determine what records are being created by the entity bean.
Simon Ingram
Ranch Hand

Joined: Nov 30, 2003
Posts: 173
OK, Roger. That's probably a good idea.
Simon Ingram
Ranch Hand

Joined: Nov 30, 2003
Posts: 173
Apologies! It was a programming error on my side. I was trying to reestablish the primary key in ejbActivate!

So, cloudscape does persist data (no real surprise) but when one encounters errors during development the ij tool provided is very poor. One cannot run proper sql queries on the database. No matter how good cloudscape may be, this fact is enough to deter one from using it. A shame for IBM.

regards,
Simon
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: entity beans that don't persist?