Win a copy of Fixing your Scrum this week in the Agile forum!

Mike Rocks

Greenhorn
+ Follow
since Oct 14, 2008
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mike Rocks

Hello Ranchers,

I am going through Enthuwares questions and I want to test the given answers. There is a question on transaction-handling like following:



I created an example but JBoss doesn't behave like mentioned above. The A-Bean doesn't get an EJBException (it can't be caught) but it gets an IllegalStateException.

Here is my code for the client-class:


The code for the ABean-class. Here the IllegalStateException raises instead of the EJBExceptio:


And the code for the BBean-class:


Why does the IllegalStateException raise in the ABean-class instead of the EJBException?
Hello Ranchers,

thanks for your replies. I found the error with your hints at the ID. I've made a fault AND Jboss has a curious behavier.

The ID was auto-generated from my database (MS SQL Server)

and therefore I couldn't set the ID myself. I overlooked this because I copied the entity from another example. :roll: Now that I don't set the ID the code works fine with persist().

BUT why does the Jboss server adds a new Cabin with the next new ID with merge(), when I set the ID myself to a different higher number and have auto-generated IDs? I think that there should come an error message like "cannot merge the entity, because no such ID in database"...

Sincerely
Mike
Hello Ranchers,

I am going through the examples of O'Reillys EJB 3.0 Book. There is an example (ex05_2) that has a J2SE-Client which make the persistence directly/self over JDBC in the hypersonic database. The client instantiates a cabin-class entity and persists it with an EntityManager like following:



When I test the code I get an error: "detached entity passed to persist". When I change the line "manager.persist(cabin_1)" to "manager.merge(cabin_1)" then the example works. The cabin_1 entity has a field marked as ID and the actual ID is definitely not yet used in the database.

Why comes this error message when I use persist?

Thank you in advance,
Mike