[EJB/JBoss] - problem with usertransaction annotation
by bridge007
Hi,
I'm trying to migrate a session bean from ejb 2.1 to ejb 3.0.
The migration is almost finished, but I have a problem while migrating
the usertransaction. I want to use an annotation.
The annotation works fine for the datasource, but for the usertransaction it has no effect. I always get a NullpointerException.
This is the code before the usertransaction migration, but with datasource migration to ejb 3.0:
@Resource protected SessionContext c_sctSContext = null;
| @Resource(mappedName="java:/LABSP_DS") javax.sql.DataSource database;
| protected javax.transaction.UserTransaction ut;
| ...
| protected Connection initTransactionWithConnection()
| throws BSConnectionTroubleException {
| Connection returnConnection = null;
|
| try {
| this.ut = this.c_sctSContext.getUserTransaction();
|
| if (this.ut.getStatus() != javax.transaction.Status.STATUS_NO_TRANSACTION) {
| getLogger()
| .debug(
| this
| + "Failure Transaction State != Status.STATUS_NO_TRANSACTION (" + this.ut.getStatus() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
|
| throw new BSConnectionTroubleException(
| "Failure Transaction State != Status.STATUS_NO_TRANSACTION (" + this.ut.getStatus() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
| }
|
| returnConnection = getConnection();
| this.ut.begin();
|
| } catch (Exception e) {
| getLogger().error("Error init connection/transaction:", e); //$NON-NLS-1$
|
| throw new BSConnectionTroubleException("Could not connect to database", e); //$NON-NLS-1$
| }
|
| return returnConnection;
| }
This code works fine.
Now my migration of the usertransaction (add of resource annotation and elemination of usertransaction lookup):
@Resource protected SessionContext c_sctSContext = null;
| @Resource(mappedName="java:/LABSP_DS") javax.sql.DataSource database;
| @Resource protected javax.transaction.UserTransaction ut;
| ...
| protected Connection initTransactionWithConnection()
| throws BSConnectionTroubleException {
| Connection returnConnection = null;
|
| try {
|
| if (this.ut.getStatus() != javax.transaction.Status.STATUS_NO_TRANSACTION) {
| getLogger()
| .debug(
| this
| + "Failure Transaction State != Status.STATUS_NO_TRANSACTION (" + this.ut.getStatus() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
|
| throw new BSConnectionTroubleException(
| "Failure Transaction State != Status.STATUS_NO_TRANSACTION (" + this.ut.getStatus() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
| }
|
| returnConnection = getConnection();
| this.ut.begin();
|
| } catch (Exception e) {
| getLogger().error("Error init connection/transaction:", e); //$NON-NLS-1$
|
| throw new BSConnectionTroubleException("Could not connect to database", e); //$NON-NLS-1$
| }
|
| return returnConnection;
| }
After this migration, I always get a NullpointerException on line:
| if (this.ut.getStatus() != javax.transaction.Status.STATUS_NO_TRANSACTION)
|
This is because the usertransaction was not injected. The question is why?
Help is welcome!
Any idea?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4126919#4126919
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4126919
18 years, 2 months
[JNDI/Naming/Network] - JBoss jboss-4.0.3SP1, NAT, RMI, -Djava.rmi.server.hostname,
by juha.makkonen@porasto.fi
Problem:
Server IP = XXX.nnn.nn.nn
Client jndi.properties file:
jndi.CommandDispatcher=ejb/SessionBeanName
java.naming.provider.url=jnp://YYY.nnn.nn.nn:1099
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
Client uses server through NAT (Network Address Translation) and YYY.nnn.nn.nn is translated to
server real ip XXX.nnn.nn.nn. Error:
javax.naming.CommunicationException [Root exception is java.rmi.ConnectException: Connection refused to host: XXX.nnn.nn.nn.
Solution that works with that client:
Server side:
- We added on the server side to run.sh file following directive: -Djava.rmi.server.hostname=server.company.com
Client side:
- We added swt-client to start with directive -Djava.rmi.server.hostname=server.company.com.
- We adeed one line to the workstations hosts file: YYY.nnn.nn.nn server.company.com
- we changed jndi.properties file: java.naming.provider.url=jnp://server.company.com:1099
After these changes it works ok with that client but not with other clients which are
connecting to server directly with real ip XXX.nnn.nn.nn.
Is there solution for both client types without using name-service ?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4126906#4126906
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4126906
18 years, 2 months