[EJB/JBoss] - Problem by jndi-lookup from Tomcat to JBoss
by thomas2008ch
Hi all,
I use the XDoclet to build EJB2-porject. The EJB2-project is deployed in JBoss 4.2.2. GA.
I can access/connect to the bean from an jsp (index.jsp) in a war:
| ...
| <body>
| <%
| com.zoo.Tiger tiger = null;
| try{
| com.zoo.TigerHome home = com.zoo.TigerUtil.getHome();
| tiger = home.create();
|
| }catch(Exception exception)
| {
|
| }
| %>
| <b><%= tiger.roar() %></b>
| </body>
| ...
|
The war is included within an ear deployed on JBoss.
I can even access/connect the bean on the server with a standalone java:
| public class TestClient {
|
| public static void main(String[] args) {
| Tiger tiger = null;
| try {
| TigerHome home = TigerUtil.getHome();
| tiger = home.create();
| System.out.println(tiger.roar());
|
| } catch (Exception exception) {
| exception.printStackTrace();
| }
| }
| }
|
With a jndi.properties:
| java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
| java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
| java.naming.provider.url=localhost:1099
|
Now I deploy the web/war on Tomcat 6 and try to access/connect to the bean on JBoss. But it failed. My "index.jsp" looks as follow:
| <body>
| <%
| Properties props = new Properties();
| props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
| props.put(Context.PROVIDER_URL, "jnp://localhost:1099");
|
| com.zoo.Tiger tiger = null;
| try{
| com.zoo.TigerHome home = com.zoo.TigerUtil.getHome();
| tiger = home.create();
|
| }catch(Exception exception)
| {
|
| }
| %>
| <b><%= tiger.roar() %></b>
| </body>
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4153212#4153212
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4153212
17 years, 11 months
[EJB 3.0] - Re: Bean Managed Transaction: No JTA transaction found
by rituraj_tiwari
No. I did not realize that would be needed since it seems to work just fine when invoked from session beans. I want to use the same, working infrastructure, but from a worker thread.
That being said, this is my persistence.xml:
| <persistence-unit name="MyProject">
| <provider>org.hibernate.ejb.HibernatePersistence</provider>
| <jta-data-source>java:/MyProjectDatasource</jta-data-source>
| <properties>
| <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
| <property name="hibernate.hbm2ddl.auto" value="update"/>
| <property name="hibernate.show_sql" value="true"/>
| <property name="hibernate.format_sql" value="true"/>
| <property name="jboss.entity.manager.factory.jndi.name" value="java:/MyProjectEntityManagerFactory"/>
| </properties>
| </persistence-unit>
|
Thanks for your help in the wee hours of the morning!
-Raj
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4153206#4153206
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4153206
17 years, 11 months
[EJB/JBoss] - Doing persistence operations in worker threads
by rituraj_tiwari
Folks,
I am running into a problem where I have come to a dead end after following several leads.
I am launching an operation asynchronously in a separate thread which gathers some info and then starts persisting some entities. Problem is, I cannot seem to get anything written to the database.
My current approach is to get the EntityManagerFactory and UserTransaction in my worker thread by doing a JNDI lookup:
| InitialContext ctx = new InitialContext();
| EntityManagerFactory emf = (EntityManagerFactory)ctx.lookup( "java:/MyProjectEntityManagerFactory" );
| UserTransaction ut = (UserTransaction)ctx.lookup( "java:comp/UserTransaction" );
|
| EntityManager em = em = emf.createEntityManager();
|
As soon as the last line above is executed, I see the following message in my JBoss log file:
| 2008-05-25 01:14:30,093 DEBUG [org.hibernate.impl.SessionImpl] opened session at
| timestamp: 4963136594300928
| 2008-05-25 01:14:30,093 DEBUG [org.hibernate.ejb.AbstractEntityManagerImpl] Looking for a JTA transaction to join
| 2008-05-25 01:14:30,093 DEBUG [org.hibernate.ejb.AbstractEntityManagerImpl] No JTA transaction found
|
All persistent operations seem to work, but nothing gets written to the DB. I see the following log messages in server.log:
| 2008-05-25 01:21:20,718 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] delaying identity-insert due to no transaction in progress
|
Is there anything I can do to start a JTA transaction?
My environment is JBoss 4.2.2 and Seam 2.x
Thanks.
-Raj
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4153204#4153204
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4153204
17 years, 11 months
[EJB 3.0] - Re: Bean Managed Transaction: No JTA transaction found
by rituraj_tiwari
An update on this issue:
I moved the entity manager creation code inside my worker thread so as to skirt any issues with transactions being threadlocal etc. I stilll cannot find a way to get a JTA transaction:
| ...
|
| InitialContext ctx = new InitialContext();
| EntityManagerFactory emf = (EntityManagerFactory)ctx.lookup( "java:/MyProjectEntityManagerFactory" );
|
| UserTransaction ut = (UserTransaction)ctx.lookup( "java:comp/UserTransaction" );
|
| ...
|
I am able to get a hold of valid objects. Still, I get the same messages about no JTA transactions being found. Of course, any persistent operations I do get queued up and don't get written to the database.
Is this a known bug in JBoss' EJB3 or Hibernate layers?
I have been hammering on this problem for three days non-stop. Any help from someone out there will be greatly appreciated.
Thanks.
-Raj
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4153200#4153200
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4153200
17 years, 11 months