开发者

How to set "unchained transaction mode" from entity manager

I am trying to call a stored procedure using native query call from an entity manager like this

String command = "..."//my stored procedure call command
Query q =  getEntityManager().createNativeQuery(command);

But when i run it I got the following message:

Exception, procedure 开发者_开发知识库... can be run only in unchained transaction mode...

I know if I have a connection object, i can set con.setAutoComit(true) to make this work. But my question is: since I have a entity manager object, can i set this somehow from entity manager object? I'd like to have the container to manage all the database resources...

I am using EclipseLink.

thanks.

One more note: i don't have the control over the database side,so i cannot go and change the transaction mode to "any".


I found the solution:

getEntityManager().createNativeQuery("set chained off").executeUpdate();


What database/JDBC driver are you using? Are you using Sybase JConnect? I think it had this issue with some stored procedure calls.

If you cannot fix the issue on the database/drvier, EclipseLink has an option for this.

Using a SessionCustomizer you can set,

session.getLogin().handleTransactionsManuallyForSybaseJConnect();

This will only work if EclipseLink has control of the transactions, not with JTA.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜