But in case of CMT we will not commit the transaction programmatically, rather Container will commit the transaction at the end. That means, entiryManager.merge() will not commit the changes until commit() is called.
Yes. But since you have wrapped your method call in a CMT this is presumably what you want? Why use CMT and try to commit early, as it were? It will have no effect, since the transaction will only really commit when the CMT commits.
Even in the EJB the method will be succesful and won't get inside catch block. After the EJBs business method is over, Container is trying to commit the transaction which is not in our scope.
By default you will be using
JDBC transactions, which (since they are run in a CMT) will commit when the transaction commits. That is, unless you have specified a different transaction manager lookup class for Hibernate to use? In CMT your try catch block needs to be round your business method call, and you need to explicitly call setRollbackOnly() when the method fails with an application exception.
I would like to handle the exception when the container is trying to commit
Well, that means you would need to use BMT, not CMT.