This content has been marked as final.
Show 1 reply
-
1. Re: Setting persistence JNDI name for PersistenceContext
jaikiran Apr 29, 2008 4:30 AM (in response to deanouk)The @PersistenceContext does not accept an attribute like jndiName, where you could have specified the jndi-name of the entitymanager.
However, i do see a way out. There's a @Resource annotation which accepts a mappedName attribute (which is nothing but the jndi-name of a resource) and also the "type" of the resource. So here's what you can do:
1) Bind the entitymanager to the JNDI. To do this, you have to add the following 2 properties to your persistence.xml:<?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence"> <persistence-unit name="msp-par"> <jta-data-source>blahblahblah</jta-data-source> ..... ..... <properties> <property name="jboss.entity.manager.jndi.name" value="java:/MyEntityManager"/> <property name="jboss.entity.manager.factory.jndi.name" value="java:/MyEntityManagerFactory"/> </properties> </persistence-unit> </persistence>
2) In your bean, inject the persistence context as follows:@Resource (type = EntityManager.class, mappedName = "java:/MyEntityManager") private EntityManager entityManager;
Does this solve your problem?