user802232
user802232

Reputation: 2611

Is it possible to mark one method of an entire @Transactional class as non-transactional

I need to maintain the transaction manually in a method of a class which was marked as @Transactional. If I try to do this now, an exception is being thrown (most probably because the transaction is being committed twice, once by me, and twice by the wrapper proxy). What do I need to do.

If this is not possible, then is there a way to get notified when a transaction was successfully committed (data in the DB and everything), so that I call another applciation, which relies on the same DB?

Upvotes: 2

Views: 1310

Answers (2)

ManuPK
ManuPK

Reputation: 11839

I hope you are using spring. If yes, then you can.

Read this block of code from the API here. at section 10.5.6 Using @Transactional

@Transactional(readOnly = true)
public class DefaultFooService implements FooService {

 public Foo getFoo(String fooName) {
// do something
}

// these settings have precedence for this method
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public void updateFoo(Foo foo) {
 // do something
}
}

Upvotes: 1

thait84
thait84

Reputation: 198

No, I don't believe this is possible. I believe if you create another thread and execute the code, it will be outside of the transaction though. Be careful with that, because it can get dicey when you are creating additional threads and managing that yourself.

Upvotes: 0

Related Questions