Fast Object Database for Java - with JPA/JDO support

Cannot catch a PersistenceException and continue the transaction

#1

I try to create a factory that creates new objects just in case it doesn't find the relevant one in the DB.

but because query.getSingleResult() fires NoResultException in that case it marks the transaction as one that need to be rolled back. I understood that I can overcome it in several ways but those don't work for me.

  1. Begin a new (nested) transaction in another method that will be rolled back instead of the first one- doesn't work. I got a message that it couldn't begin a new transaction when another is active.
  2. Searching the relevant object outside a transaction using @TransactionalAttribute(TransactionType.NOT_SUPPORTED) - doesn't work for me because i need to find also objects created in the same transaction.
  3. Implement a BMT- it doesn't let me commit and rollback because the server is also trying to do so.

How can I do so?

 

I use Glassfish 3.1.2.2 open source ee6 edition, eclipse juno on Windows 7 64

 

Hope to get a n usefull answer,

Ophir :)

Thanks, Dreckguy
text/x-java icon Factory.java (5.48 KB)
The main Factory
text/x-java icon Finder.java (4.69 KB)
The object responsible to query the db
#2

You may catch the exception in the method.

If the exception is caught by the application and not thrown to the application server, the transaction is not expected to be marked for rollback.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
#3

Ohh, I see.

Thx!

Thanks, Dreckguy

Post Reply