English 中文(简体)
does ejb commits on connection?
原标题:

i am using session bean in my application and transaction is controlled at EJB layer only. The problem that i am facing is with some commit. I am using the same connection as used by EJB to insert into one table, but if the transaction is committed then that insert is not committed into the database.. can any one help me with the problem..

最佳回答

I m not an EJB expert, I usually work with plain old java objects, but...

Your problem probably has to do with the fact that EJBs don t do transaction management on the connection level. They use the Java Transaction Service to create transactions that can use multiple connections. So for your insert to become part of the EJB s transaction you have to obtain that transaction from the transaction server and make your insert part of that transaction. I believe that how you do this exactly depends on what kind of EJB environment you have (EJB2 or 3 and so on)

But if your in an EJB environment and want to insert stuff within the same transactions as a EJB does its stuff, would it not make sense to also make an EJB for the table that you want to insert into and let the application server figure it out?

问题回答

General, simplified, answer to your question is yes, Connection.commit() is called when EJB is committed.

What EJB actually does depends on how the datasource is defined (transactional or not) and if the last resource optimization is allowed.

I am using the same connection as used by EJB

How do you know? Some connection wrappers (e.g. Weblogic one, if I remember right) have no way to compare two connections for equality. To do that one need to use a vendor API. So even if you think two connections are the same, it s not necessary the case.

How did you get that connection? From where? Depending on EJB version you should only get connection from transactional datasource (EJB2) or use persistence context and JPA (EJB3). Some simplified code of what you do would greatly help to point onto your mistake.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签