Thursday, March 3, 2011

Validate outside the Transaction

Some debate today over whether validation should be done outside or inside a transaction.
For me it's a no-brainer that you should start the transaction only when you need it. And you don't need it to validate your data.


So, I shall create a validate() method with TransactionAttributeType SUPPORTS and a persist() method with REQUIRED.

See also
http://download.oracle.com/javaee/6/api/javax/ejb/TransactionAttribute.html

Of course we use CMT.

See also tips here.


@TransactionManagement(TransactionManagementType.CONTAINER)

@TransactionAttribute(TransactionAttributeType.REQUIRED)

No comments: