then change the entityObj by using its setters, and commit the JTA transaction , changed data is geting saved in table without calling persist() or merge().
after this, data in table changes in column mapped to for field1.
What can be the problem?
welcome to the ranch!
This is how it is intended to work. merge is used when you want to reattach a detached object to the managed persistence context so it is irrelevant for your example. persist adds an unmanaged entity to the managed persistence context. Changes in managed entities are persisted when the transaction is committed.
See here for the JPA lifecycle.
If you want more explicit control then a framework like iBatis is for you.
persist() and merge() are not simple "save" commands. They change the state of an entity regarding the current persistence context (Hibernate session). If the entity is managed, changes will be persisted once the transaction is committed. If the bean is detached, changes are lost, unless you merge the entity into the session - that is what merge() is for. If you get an entity from the entity manager (by find() or get()) it is managed.
chirag jain wrote:As I have described in my previous post, I have tried by closing entity manager, but not working...
entitymanager = createEntityManager();
entityObj = entitymanager.find();
I don't know how your closeEntityManager method works. But you can't commit a transaction to a closed entity manager. And, if you are committing successfully, changes are persisted, as expected. Entity manager and transaction should be nested, the transaction within the entity manager.
Entity manager and transaction should be nested, the transaction within the entity manager.
This transaction is not hibernate transaction. This is JTA transaction and we are using it with EJB 2.0.
My jpa work is done inside session ejb method, so entity manager has to be nested in JTA transaction.