[jboss-user] [JNDI/Naming/Network] - Re: jndi jboss service problem connecting
ByDcc
do-not-reply at jboss.com
Fri Nov 2 16:04:06 EDT 2007
Thanks for your help.
I think I needed to read a lot about this issue.
Now, I've got to lookup a datasource and got a connection. It was only a test.
But, I really want to lookup an entity manager for my persistence unit.
My code is:
Properties ht = new Properties();
| ht.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
| ht.put("java.naming.provider.url", "jnp://localhost:1099");
| ht.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
|
| Context ic = new InitialContext(ht);
|
| Object obj=ic.lookup("cartstore");
| EntityManager em = (EntityManager) obj;
|
| CategoryEntity ce = new CategoryEntity();
| ce.setCreationDate(new Timestamp( Calendar.getInstance().getTimeInMillis() ) );
| ...
| em.persist(ce);
But a I get a null reference to my entity manager.
Persistence unit definition:
<persistence>
| <persistence-unit name="cartstore">
| <!--jta-data-source>java:/CartStoreDS</jta-data-source-->
| <jta-data-source>CartStoreDS</jta-data-source>
| <class>com.cartstore.persistence.domain.model.CategoryEntity</class>
| <class>com.cartstore.persistence.domain.model.ItemEntity</class>
|
| <properties>
| <property name="jboss.entity.manager.jndi.name" value="cartstore"/>
| <property name="jboss.entity.manager.factory.jndi.name" value="CartstoreFactory"/>
| </properties>
| </persistence-unit>
| </persistence>
jboss.entity.manager.jndi.name property force to jboss to public my persistence unit in global jndi section,
reference: http://docs.jboss.org/ejb3/app-server/reference/build/reference/en/html/entityconfig.html
Info from JNDIView:
Global JNDI Namespace
......
+- persistence.units:unitName=cartstore (class: org.hibernate.impl.SessionFactoryImpl)
.....
+- CartStoreDS (class: javax.sql.DataSource)
....
I know that I could test it with a EJB3StandaloneDeployer (JBoss) but I would like to do a fisrt test as simple as posible.
Any idea of why I am not be able to see my entity manager will be appreciated.
Thank you in advance.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4101454#4101454
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4101454
More information about the jboss-user
mailing list