Wesley Wu wrote:
> Not a version issue.
>
> An entitymanager should not get transaction by itself. Transaction in
> a modern java appserver should be XA or JTA transaciton.
> An entitymanager will detect if there is a JTA transaction existing
> and will join it if there is an open one.
>
> You need to use an injected UserTransaction instance to do the
> transaction stuff and leave the entitymanager do db stuff and the
> entitymanager will participate in the transaction.
>   
Also, if you absolutely need to use the EntityTransaction, you'd need to 
grab the EntityManagerFactory, not the EntityManager. The EntityManager 
is tied into the container's transaction manager.

The UserTransaction is registered with CanDI, by the way, so it's easy 
to grab:

public class MyBean {
  @Inject UserTransaction _ut;

  ...
}

-- Scott
> -Wesley
>
> 2010/3/29 Stargazer <starga...@blueyonder.co.uk>
>   
>> On 27-Mar-2010 01:10, Stargazer wrote:
>>     
>>> Resin 4.0.5 - following http://wiki.caucho.com/Hibernate works fine, but
>>> I'd like to take it to the next level and persist something.
>>> Adding
>>>           EntityTransaction tx = _manager.getTransaction();
>>>           tx.begin();
>>>           ...
>>> to the end of the CourseServlet.java file throws up
>>>
>>> java.lang.IllegalStateException: Container-manager @PersistenceContext
>>> may not use getTransaction.
>>>
>>> What have I missed please?
>>>
>>>
>>>
>>> _______________________________________________
>>> resin-interest mailing list
>>> resin-interest@caucho.com
>>> http://maillist.caucho.com/mailman/listinfo/resin-interest
>>>
>>>
>>>       
>> Could anyone tell me if this worked in an earlier vrsion of resin please?
>> Its the first time I've tried hibernate with resin, and I can't tell if
>> its something I'm doing (or not doing!) here or related to an issue in
>> 4.0.5.
>>
>>
>>
>> _______________________________________________
>> resin-interest mailing list
>> resin-interest@caucho.com
>> http://maillist.caucho.com/mailman/listinfo/resin-interest
>>     
>
>
> _______________________________________________
> resin-interest mailing list
> resin-interest@caucho.com
> http://maillist.caucho.com/mailman/listinfo/resin-interest
>
>   



_______________________________________________
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest

Reply via email to