JPA component in a JEE5 environment: EntityManagerFactory from JNDI

View: New views
8 Messages — Rating Filter:   Alert me  

JPA component in a JEE5 environment: EntityManagerFactory from JNDI

by B_A :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

- Camel 2.0M3
- Camel-JPA 2.0M3
- Weblogic 10
- Hibernate-Core 3.3.0.SP1
- Hibernate-EntityManager 3.4.0.GA
- Configuration in Spring XML


Hi,

I tried to make use of the jpa component. But I have problems to get an EntityManagerFactory from JNDI on Weblogic 10. As described in the Spring JPA Documentation I do a JNDI-Lookup. persistence-unit-ref entries are defined in the Java EE deployment descriptor (ejb-jar.xml).

The Exception is:

javax.naming.NameNotFoundException: Unable to resolve 'TMD_PERSISTENCE'. Resolved ''; remaining name 'TMD_PERSISTENCE'
        at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1138)
        at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:251)
        at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:171)
        at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:205)
        at weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:254)
        at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:367)
        at javax.naming.InitialContext.lookup(InitialContext.java:351)
        at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155)
        at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:88)
        at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:153)
        at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)

Can anybody give me a hint what i am doing wrong?

Thanks,
Bernd Altmiks

My Camel-Context:
...
<jee:jndi-lookup id="eMFactory" jndi-name="TMD_PERSISTENCE"/>

<bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent">
        <property name="entityManagerFactory" ref="eMFactory" />
        <property name="transactionManager" ref="txManager" />
</bean>

<bean id="txManager" class="org.springframework.transaction.jta.WebLogicJtaTransactionManager"/>
...


My ejb-jar.xml

<?xml version="1.0" encoding="UTF-8"?>

<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
        version="3.0">
        <enterprise-beans>

                <session>
                        <ejb-name>ITMDClientDAO</ejb-name>
                        <ejb-class>tmd.al.dao.TMDClientDAO</ejb-class>
                        <session-type>Stateless</session-type>
                        <persistence-unit-ref>
                                <persistence-unit-ref-name>TMD_PERSISTENCE</persistence-unit-ref-name>
                                <persistence-unit-name>TMD_PERSISTENCE</persistence-unit-name>
                                <mapped-name>TMD_PERSISTENCE</mapped-name>
                        </persistence-unit-ref>
                </session>
        </enterprise-beans>
</ejb-jar>


My persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"
        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
  <persistence-unit name="TMD_PERSISTENCE" transaction-type="JTA">    
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>com.mummert.tributum.tbpersistence.TributumDataSource</jta-data-source>      
        <class>tmd.al.entity.TMDMessage</class>
    <properties>
      <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>            
      <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.WeblogicTransactionManagerLookup" />
      <property name="hibernate.show_sql" value="false" />
      <property name="hibernate.format_sql" value="false" />      
      <property name="hibernate.use_sql_comments" value="false"/>
      <property name="hibernate.generate_statistics" value="false" />    
           <property name="hibernate.jndi.weblogic.jndi.replicateBindings" value="false" />
            <property name="hibernate.query.factory_class" value="org.hibernate.hql.classic.ClassicQueryTranslatorFactory"/>
      <property name="hibernate.cache.use_second_level_cache" value="false"/>      
    </properties>
  </persistence-unit>
</persistence>


Re: JPA component in a JEE5 environment: EntityManagerFactory from JNDI

by Claus Ibsen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi

That is the same s*** with the J2ee servers and the JNDI lookup. Its
painful when it does not work and you need to setup all kind
of indirections in various deployment descriptors both standard j2ee
related and server specific.

I will try googling and look at WebLogic documentation as its a pure
WebLogic + Spring J2ee lookup thingy.



On Mon, Aug 31, 2009 at 10:31 AM,
BAltmiks<bernd.altmiks@...> wrote:

>
> - Camel 2.0M3
> - Camel-JPA 2.0M3
> - Weblogic 10
> - Hibernate-Core 3.3.0.SP1
> - Hibernate-EntityManager 3.4.0.GA
> - Configuration in Spring XML
>
>
> Hi,
>
> I tried to make use of the jpa component. But I have problems to get an
> EntityManagerFactory from JNDI on Weblogic 10. As described in the
> http://static.springsource.org/spring/docs/2.5.x/reference/orm.html#orm-jpa
> Spring JPA Documentation  I do a JNDI-Lookup. persistence-unit-ref entries
> are defined in the Java EE deployment descriptor (ejb-jar.xml).
>
> The Exception is:
>
> javax.naming.NameNotFoundException: Unable to resolve 'TMD_PERSISTENCE'.
> Resolved ''; remaining name 'TMD_PERSISTENCE'
>        at
> weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1138)
>        at
> weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:251)
>        at
> weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:171)
>        at
> weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:205)
>        at
> weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:254)
>        at
> weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:367)
>        at javax.naming.InitialContext.lookup(InitialContext.java:351)
>        at
> org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155)
>        at
> org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:88)
>        at
> org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:153)
>        at
> org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
>
> Can anybody give me a hint what i am doing wrong?
>
> Thanks,
> Bernd Altmiks
>
> My Camel-Context:
> ...
> <jee:jndi-lookup id="eMFactory" jndi-name="TMD_PERSISTENCE"/>
>
> <bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent">
>        <property name="entityManagerFactory" ref="eMFactory" />
>        <property name="transactionManager" ref="txManager" />
> </bean>
>
> <bean id="txManager"
> class="org.springframework.transaction.jta.WebLogicJtaTransactionManager"/>
> ...
>
>
> My ejb-jar.xml
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
> http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
>        version="3.0">
>        <enterprise-beans>
>
>                <session>
>                        <ejb-name>ITMDClientDAO</ejb-name>
>                        <ejb-class>tmd.al.dao.TMDClientDAO</ejb-class>
>                        <session-type>Stateless</session-type>
>                        <persistence-unit-ref>
>                                <persistence-unit-ref-name>TMD_PERSISTENCE</persistence-unit-ref-name>
>                                <persistence-unit-name>TMD_PERSISTENCE</persistence-unit-name>
>                                <mapped-name>TMD_PERSISTENCE</mapped-name>
>                        </persistence-unit-ref>
>                </session>
>        </enterprise-beans>
> </ejb-jar>
>
>
> My persistence.xml
>
> <?xml version="1.0" encoding="UTF-8"?>
> <persistence xmlns="http://java.sun.com/xml/ns/persistence"
>        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"
>        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
> http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
>  <persistence-unit name="TMD_PERSISTENCE" transaction-type="JTA">
>    <provider>org.hibernate.ejb.HibernatePersistence</provider>
>
> <jta-data-source>com.mummert.tributum.tbpersistence.TributumDataSource</jta-data-source>
>        <class>tmd.al.entity.TMDMessage</class>
>    <properties>
>      <property name="hibernate.dialect"
> value="org.hibernate.dialect.Oracle10gDialect"/>
>      <property name="hibernate.transaction.manager_lookup_class"
> value="org.hibernate.transaction.WeblogicTransactionManagerLookup" />
>      <property name="hibernate.show_sql" value="false" />
>      <property name="hibernate.format_sql" value="false" />
>      <property name="hibernate.use_sql_comments" value="false"/>
>      <property name="hibernate.generate_statistics" value="false" />
>           <property name="hibernate.jndi.weblogic.jndi.replicateBindings"
> value="false" />
>            <property name="hibernate.query.factory_class"
> value="org.hibernate.hql.classic.ClassicQueryTranslatorFactory"/>
>      <property name="hibernate.cache.use_second_level_cache"
> value="false"/>
>    </properties>
>  </persistence-unit>
> </persistence>
>
>
> --
> View this message in context: http://www.nabble.com/JPA-component-in-a-JEE5-environment%3A-EntityManagerFactory-from-JNDI-tp25219979p25219979.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



--
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: JPA component in a JEE5 environment: EntityManagerFactory from JNDI

by B_A :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Claus,

this is what the Oracle-Support says. I will try these.


Hello Bernd,

I tried calling you regarding the issue, however couldn't reach.

As per the issue I understand that you are using trying to lookup the  
Entity Manager instance and you are trying to use Entity Manager  
Factory, but you do not wish to use injection of .@PersistenceContext.

Please let me know if you are using any JPA provider (e.g. kodo,  
hibernate etc).

In JEE the EntityManager or EntityManagerFactory can either be looked  
up in JNDI, or injected into a SessionBean. To look up the  
EntityManager in JNDI it must be published in JNDI such as through a  
<persistence-context-ref> in a SessionBean's ejb-jar.xml file. To  
inject an EntityManager or EntityManagerFactory the  
annotation .@PersistenceContext or .@PersistenceUnit are used.

For your reference I am adding both the options (annotation / non-
annota)

Example SessionBean ejb-jar.xml file with persistence context

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
version="3.0">
<enterprise-beans>
<session>
<ejb-name>EmployeeService</ejb-name>
<business-remote>org.acme.EmployeeService</business-remote>
<ejb-class>org.acme.EmployeeServiceBean</ejb-class>
<session-type>Stateless</session-type>
<persistence-context-ref>
<persistence-context-ref-name>persistence/acme/entity-manager</
persistence-context-ref-name>
<persistence-unit-name>acme</persistence-unit-name>
</persistence-context-ref>
<persistence-unit-ref>
<persistence-unit-ref-name>persistence/acme/factory</persistence-unit-
ref-name>
<persistence-unit-name>acme</persistence-unit-name>
</persistence-unit-ref>
</session>
</enterprise-beans>
</ejb-jar>

Example of looking up an EntityManager in JNDI
===============================================

InitialContext context = new InitialContext();
EntityManager entityManager = (EntityManager)context.lookup("java:comp/
env/persistence/acme/entity-manager");
...

Example of looking up an EntityManagerFactory in JNDI
=====================================================

InitialContext context = new InitialContext();
EntityManagerFactory factory = (EntityManagerFactory)context.lookup
("java:comp/env/persistence/acme/factory");
...

Example of injecting an EntityManager and EntityManagerFactory
===============================================================

.@Stateless(name="EmployeeService", mappedName="acme/EmployeeService")
.@Remote(EmployeeService.class)
public class EmployeeServiceBean implements EmployeeService {

.@PersistenceContext(unitName="acme")
private EntityManager entityManager;

.@PersistenceUnit(unitName="acme")
private EntityManagerFactory factory;
...
}

Please feel free to get back to me in case of any doubt or query  
regarding the same.


Regards,
Saumajit Das





>
Claus Ibsen-2 wrote:
>Hi
>
>That is the same s*** with the J2ee servers and the JNDI lookup. Its
>painful when it does not work and you need to setup all kind
>of indirections in various deployment descriptors both standard j2ee
>related and server specific.
>
>I will try googling and look at WebLogic documentation as its a pure
>WebLogic + Spring J2ee lookup thingy.



On Mon, Aug 31, 2009 at 10:31 AM,
BAltmiks<bernd.altmiks@steria-mummert.de> wrote:
>
> - Camel 2.0M3
> - Camel-JPA 2.0M3
> - Weblogic 10
> - Hibernate-Core 3.3.0.SP1
> - Hibernate-EntityManager 3.4.0.GA
> - Configuration in Spring XML
>
>
> Hi,
>
> I tried to make use of the jpa component. But I have problems to get an
> EntityManagerFactory from JNDI on Weblogic 10. As described in the
> http://static.springsource.org/spring/docs/2.5.x/reference/orm.html#orm-jpa
> Spring JPA Documentation  I do a JNDI-Lookup. persistence-unit-ref entries
> are defined in the Java EE deployment descriptor (ejb-jar.xml).
>
> The Exception is:
>
> javax.naming.NameNotFoundException: Unable to resolve 'TMD_PERSISTENCE'.
> Resolved ''; remaining name 'TMD_PERSISTENCE'
>        at
> weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1138)
>        at
> weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:251)
>        at
> weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:171)
>        at
> weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:205)
>        at
> weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:254)
>        at
> weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:367)
>        at javax.naming.InitialContext.lookup(InitialContext.java:351)
>        at
> org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155)
>        at
> org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:88)
>        at
> org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:153)
>        at
> org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
>
> Can anybody give me a hint what i am doing wrong?
>
> Thanks,
> Bernd Altmiks
>
> My Camel-Context:
> ...
> <jee:jndi-lookup id="eMFactory" jndi-name="TMD_PERSISTENCE"/>
>
> <bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent">
>        <property name="entityManagerFactory" ref="eMFactory" />
>        <property name="transactionManager" ref="txManager" />
> </bean>
>
> <bean id="txManager"
> class="org.springframework.transaction.jta.WebLogicJtaTransactionManager"/>
> ...
>
>
> My ejb-jar.xml
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
> http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
>        version="3.0">
>        <enterprise-beans>
>
>                <session>
>                        <ejb-name>ITMDClientDAO</ejb-name>
>                        <ejb-class>tmd.al.dao.TMDClientDAO</ejb-class>
>                        <session-type>Stateless</session-type>
>                        <persistence-unit-ref>
>                                <persistence-unit-ref-name>TMD_PERSISTENCE</persistence-unit-ref-name>
>                                <persistence-unit-name>TMD_PERSISTENCE</persistence-unit-name>
>                                <mapped-name>TMD_PERSISTENCE</mapped-name>
>                        </persistence-unit-ref>
>                </session>
>        </enterprise-beans>
> </ejb-jar>
>
>
> My persistence.xml
>
> <?xml version="1.0" encoding="UTF-8"?>
> <persistence xmlns="http://java.sun.com/xml/ns/persistence"
>        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"
>        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
> http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
>  <persistence-unit name="TMD_PERSISTENCE" transaction-type="JTA">
>    <provider>org.hibernate.ejb.HibernatePersistence</provider>
>
> <jta-data-source>com.mummert.tributum.tbpersistence.TributumDataSource</jta-data-source>
>        <class>tmd.al.entity.TMDMessage</class>
>    <properties>
>      <property name="hibernate.dialect"
> value="org.hibernate.dialect.Oracle10gDialect"/>
>      <property name="hibernate.transaction.manager_lookup_class"
> value="org.hibernate.transaction.WeblogicTransactionManagerLookup" />
>      <property name="hibernate.show_sql" value="false" />
>      <property name="hibernate.format_sql" value="false" />
>      <property name="hibernate.use_sql_comments" value="false"/>
>      <property name="hibernate.generate_statistics" value="false" />
>           <property name="hibernate.jndi.weblogic.jndi.replicateBindings"
> value="false" />
>            <property name="hibernate.query.factory_class"
> value="org.hibernate.hql.classic.ClassicQueryTranslatorFactory"/>
>      <property name="hibernate.cache.use_second_level_cache"
> value="false"/>
>    </properties>
>  </persistence-unit>
> </persistence>
>
>
> --
> View this message in context: http://www.nabble.com/JPA-component-in-a-JEE5-environment%3A-EntityManagerFactory-from-JNDI-tp25219979p25219979.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



--
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: JPA component in a JEE5 environment: EntityManagerFactory from JNDI

by Claus Ibsen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, Sep 3, 2009 at 2:55 PM, BAltmiks<bernd.altmiks@...> wrote:
>
> Hi Claus,
>
> thank your for your help!
>
> This is what the Oracle-Support says. I will try these.

Thanks for sharing this.
Yeah the jnid lookup is cumbersome :)


>
>
> Hello Bernd,
>
> I tried calling you regarding the issue, however couldn't reach.
>
> As per the issue I understand that you are using trying to lookup the
> Entity Manager instance and you are trying to use Entity Manager
> Factory, but you do not wish to use injection of .@PersistenceContext.
>
> Please let me know if you are using any JPA provider (e.g. kodo,
> hibernate etc).
>
> In JEE the EntityManager or EntityManagerFactory can either be looked
> up in JNDI, or injected into a SessionBean. To look up the
> EntityManager in JNDI it must be published in JNDI such as through a
> <persistence-context-ref> in a SessionBean's ejb-jar.xml file. To
> inject an EntityManager or EntityManagerFactory the
> annotation .@PersistenceContext or .@PersistenceUnit are used.
>
> For your reference I am adding both the options (annotation / non-
> annota)
>
> Example SessionBean ejb-jar.xml file with persistence context
>
> <?xml version="1.0" encoding="UTF-8"?>
> <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
> http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
> version="3.0">
> <enterprise-beans>
> <session>
> <ejb-name>EmployeeService</ejb-name>
> <business-remote>org.acme.EmployeeService</business-remote>
> <ejb-class>org.acme.EmployeeServiceBean</ejb-class>
> <session-type>Stateless</session-type>
> <persistence-context-ref>
> <persistence-context-ref-name>persistence/acme/entity-manager</
> persistence-context-ref-name>
> <persistence-unit-name>acme</persistence-unit-name>
> </persistence-context-ref>
> <persistence-unit-ref>
> <persistence-unit-ref-name>persistence/acme/factory</persistence-unit-
> ref-name>
> <persistence-unit-name>acme</persistence-unit-name>
> </persistence-unit-ref>
> </session>
> </enterprise-beans>
> </ejb-jar>
>
> Example of looking up an EntityManager in JNDI
> ===============================================
>
> InitialContext context = new InitialContext();
> EntityManager entityManager = (EntityManager)context.lookup("java:comp/
> env/persistence/acme/entity-manager");
> ...
>
> Example of looking up an EntityManagerFactory in JNDI
> =====================================================
>
> InitialContext context = new InitialContext();
> EntityManagerFactory factory = (EntityManagerFactory)context.lookup
> ("java:comp/env/persistence/acme/factory");
> ...
>
> Example of injecting an EntityManager and EntityManagerFactory
> ===============================================================
>
> .@Stateless(name="EmployeeService", mappedName="acme/EmployeeService")
> .@Remote(EmployeeService.class)
> public class EmployeeServiceBean implements EmployeeService {
>
> .@PersistenceContext(unitName="acme")
> private EntityManager entityManager;
>
> .@PersistenceUnit(unitName="acme")
> private EntityManagerFactory factory;
> ...
> }
>
> Please feel free to get back to me in case of any doubt or query
> regarding the same.
>
>
> Regards,
> Saumajit Das
>
>
>
>
>
>>
> Claus Ibsen-2 wrote:
>>
>>>Hi
>>>
>>>That is the same s*** with the J2ee servers and the JNDI lookup. Its
>>>painful when it does not work and you need to setup all kind
>>>of indirections in various deployment descriptors both standard j2ee
>>>related and server specific.
>>>
>>>I will try googling and look at WebLogic documentation as its a pure
>>>WebLogic + Spring J2ee lookup thingy.
>>
>>
>>
>> On Mon, Aug 31, 2009 at 10:31 AM,
>> BAltmiks<bernd.altmiks@...> wrote:
>>>
>>> - Camel 2.0M3
>>> - Camel-JPA 2.0M3
>>> - Weblogic 10
>>> - Hibernate-Core 3.3.0.SP1
>>> - Hibernate-EntityManager 3.4.0.GA
>>> - Configuration in Spring XML
>>>
>>>
>>> Hi,
>>>
>>> I tried to make use of the jpa component. But I have problems to get an
>>> EntityManagerFactory from JNDI on Weblogic 10. As described in the
>>> http://static.springsource.org/spring/docs/2.5.x/reference/orm.html#orm-jpa
>>> Spring JPA Documentation  I do a JNDI-Lookup. persistence-unit-ref
>>> entries
>>> are defined in the Java EE deployment descriptor (ejb-jar.xml).
>>>
>>> The Exception is:
>>>
>>> javax.naming.NameNotFoundException: Unable to resolve 'TMD_PERSISTENCE'.
>>> Resolved ''; remaining name 'TMD_PERSISTENCE'
>>>        at
>>> weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1138)
>>>        at
>>> weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:251)
>>>        at
>>> weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:171)
>>>        at
>>> weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:205)
>>>        at
>>> weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:254)
>>>        at
>>> weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:367)
>>>        at javax.naming.InitialContext.lookup(InitialContext.java:351)
>>>        at
>>> org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155)
>>>        at
>>> org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:88)
>>>        at
>>> org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:153)
>>>        at
>>> org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
>>>
>>> Can anybody give me a hint what i am doing wrong?
>>>
>>> Thanks,
>>> Bernd Altmiks
>>>
>>> My Camel-Context:
>>> ...
>>> <jee:jndi-lookup id="eMFactory" jndi-name="TMD_PERSISTENCE"/>
>>>
>>> <bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent">
>>>        <property name="entityManagerFactory" ref="eMFactory" />
>>>        <property name="transactionManager" ref="txManager" />
>>> </bean>
>>>
>>> <bean id="txManager"
>>> class="org.springframework.transaction.jta.WebLogicJtaTransactionManager"/>
>>> ...
>>>
>>>
>>> My ejb-jar.xml
>>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>>
>>> <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>>        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
>>> http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
>>>        version="3.0">
>>>        <enterprise-beans>
>>>
>>>                <session>
>>>                        <ejb-name>ITMDClientDAO</ejb-name>
>>>                        <ejb-class>tmd.al.dao.TMDClientDAO</ejb-class>
>>>                        <session-type>Stateless</session-type>
>>>                        <persistence-unit-ref>
>>>
>>>  <persistence-unit-ref-name>TMD_PERSISTENCE</persistence-unit-ref-name>
>>>
>>>  <persistence-unit-name>TMD_PERSISTENCE</persistence-unit-name>
>>>                                <mapped-name>TMD_PERSISTENCE</mapped-name>
>>>                        </persistence-unit-ref>
>>>                </session>
>>>        </enterprise-beans>
>>> </ejb-jar>
>>>
>>>
>>> My persistence.xml
>>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <persistence xmlns="http://java.sun.com/xml/ns/persistence"
>>>        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>> version="1.0"
>>>        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
>>> http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
>>>  <persistence-unit name="TMD_PERSISTENCE" transaction-type="JTA">
>>>    <provider>org.hibernate.ejb.HibernatePersistence</provider>
>>>
>>> <jta-data-source>com.mummert.tributum.tbpersistence.TributumDataSource</jta-data-source>
>>>        <class>tmd.al.entity.TMDMessage</class>
>>>    <properties>
>>>      <property name="hibernate.dialect"
>>> value="org.hibernate.dialect.Oracle10gDialect"/>
>>>      <property name="hibernate.transaction.manager_lookup_class"
>>> value="org.hibernate.transaction.WeblogicTransactionManagerLookup" />
>>>      <property name="hibernate.show_sql" value="false" />
>>>      <property name="hibernate.format_sql" value="false" />
>>>      <property name="hibernate.use_sql_comments" value="false"/>
>>>      <property name="hibernate.generate_statistics" value="false" />
>>>           <property name="hibernate.jndi.weblogic.jndi.replicateBindings"
>>> value="false" />
>>>            <property name="hibernate.query.factory_class"
>>> value="org.hibernate.hql.classic.ClassicQueryTranslatorFactory"/>
>>>      <property name="hibernate.cache.use_second_level_cache"
>>> value="false"/>
>>>    </properties>
>>>  </persistence-unit>
>>> </persistence>
>>>
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/JPA-component-in-a-JEE5-environment%3A-EntityManagerFactory-from-JNDI-tp25219979p25219979.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>>
>> --
>> Claus Ibsen
>> Apache Camel Committer
>>
>> Open Source Integration: http://fusesource.com
>> Blog: http://davsclaus.blogspot.com/
>> Twitter: http://twitter.com/davsclaus
>>
>>
>
> --
> View this message in context: http://www.nabble.com/JPA-component-in-a-JEE5-environment%3A-EntityManagerFactory-from-JNDI-tp25219979p25275422.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



--
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: JPA component in a JEE5 environment: EntityManagerFactory from JNDI

by B_A () :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

BAltmiks wrote:
Hi Claus,

this is what the Oracle-Support says. I will try these.

.....
Doesn't work on Weblogic. There is no way to get the EntityManager from JNDI with Camel/Spring. Here is the answer from the Oracle-Support:

"According the EJB3 specification, you need to lookup the entitymanagerfactory from the same container (from any servlet or session bean running on that container)."

On Weblogic you can only obtain the EntityManagerFacotry if you are "inside" an Session bean or an Servlet. So no chance to do a lookup with <jee:jndi-lookup> in my camel-context.xml (Spring Bases XML Configuration)

Regards,
Bernd


Re: JPA component in a JEE5 environment: EntityManagerFactory from JNDI

by Claus Ibsen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, Oct 26, 2009 at 10:13 AM, BAltmiks
<bernd.altmiks@...> wrote:

>
>
>
> BAltmiks wrote:
>>
>> Hi Claus,
>>
>> this is what the Oracle-Support says. I will try these.
>>
>>
>> Hello Bernd,
>>
>> I tried calling you regarding the issue, however couldn't reach.
>>
>> As per the issue I understand that you are using trying to lookup the
>> Entity Manager instance and you are trying to use Entity Manager
>> Factory, but you do not wish to use injection of .@PersistenceContext.
>>
>> Please let me know if you are using any JPA provider (e.g. kodo,
>> hibernate etc).
>>
>> In JEE the EntityManager or EntityManagerFactory can either be looked
>> up in JNDI, or injected into a SessionBean. To look up the
>> EntityManager in JNDI it must be published in JNDI such as through a
>> <persistence-context-ref> in a SessionBean's ejb-jar.xml file. To
>> inject an EntityManager or EntityManagerFactory the
>> annotation .@PersistenceContext or .@PersistenceUnit are used.
>>
>> For your reference I am adding both the options (annotation / non-
>> annota)
>>
>> Example SessionBean ejb-jar.xml file with persistence context
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
>> http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
>> version="3.0">
>> <enterprise-beans>
>> <session>
>> <ejb-name>EmployeeService</ejb-name>
>> <business-remote>org.acme.EmployeeService</business-remote>
>> <ejb-class>org.acme.EmployeeServiceBean</ejb-class>
>> <session-type>Stateless</session-type>
>> <persistence-context-ref>
>> <persistence-context-ref-name>persistence/acme/entity-manager</
>> persistence-context-ref-name>
>> <persistence-unit-name>acme</persistence-unit-name>
>> </persistence-context-ref>
>> <persistence-unit-ref>
>> <persistence-unit-ref-name>persistence/acme/factory</persistence-unit-
>> ref-name>
>> <persistence-unit-name>acme</persistence-unit-name>
>> </persistence-unit-ref>
>> </session>
>> </enterprise-beans>
>> </ejb-jar>
>>
>> Example of looking up an EntityManager in JNDI
>> ===============================================
>>
>> InitialContext context = new InitialContext();
>> EntityManager entityManager = (EntityManager)context.lookup("java:comp/
>> env/persistence/acme/entity-manager");
>> ...
>>
>> Example of looking up an EntityManagerFactory in JNDI
>> =====================================================
>>
>> InitialContext context = new InitialContext();
>> EntityManagerFactory factory = (EntityManagerFactory)context.lookup
>> ("java:comp/env/persistence/acme/factory");
>> ...
>>
>> Example of injecting an EntityManager and EntityManagerFactory
>> ===============================================================
>>
>> .@Stateless(name="EmployeeService", mappedName="acme/EmployeeService")
>> .@Remote(EmployeeService.class)
>> public class EmployeeServiceBean implements EmployeeService {
>>
>> .@PersistenceContext(unitName="acme")
>> private EntityManager entityManager;
>>
>> .@PersistenceUnit(unitName="acme")
>> private EntityManagerFactory factory;
>> ...
>> }
>>
>> Please feel free to get back to me in case of any doubt or query
>> regarding the same.
>>
>>
>> Regards,
>> Saumajit Das
>>
>>
>>
>>
>>
>>>
>> Claus Ibsen-2 wrote:
>>>
>>>>Hi
>>>>
>>>>That is the same s*** with the J2ee servers and the JNDI lookup. Its
>>>>painful when it does not work and you need to setup all kind
>>>>of indirections in various deployment descriptors both standard j2ee
>>>>related and server specific.
>>>>
>>>>I will try googling and look at WebLogic documentation as its a pure
>>>>WebLogic + Spring J2ee lookup thingy.
>>>
>>>
>>>
>>> On Mon, Aug 31, 2009 at 10:31 AM,
>>> BAltmiks<bernd.altmiks@...> wrote:
>>>>
>>>> - Camel 2.0M3
>>>> - Camel-JPA 2.0M3
>>>> - Weblogic 10
>>>> - Hibernate-Core 3.3.0.SP1
>>>> - Hibernate-EntityManager 3.4.0.GA
>>>> - Configuration in Spring XML
>>>>
>>>>
>>>> Hi,
>>>>
>>>> I tried to make use of the jpa component. But I have problems to get an
>>>> EntityManagerFactory from JNDI on Weblogic 10. As described in the
>>>> http://static.springsource.org/spring/docs/2.5.x/reference/orm.html#orm-jpa
>>>> Spring JPA Documentation  I do a JNDI-Lookup. persistence-unit-ref
>>>> entries
>>>> are defined in the Java EE deployment descriptor (ejb-jar.xml).
>>>>
>>>> The Exception is:
>>>>
>>>> javax.naming.NameNotFoundException: Unable to resolve 'TMD_PERSISTENCE'.
>>>> Resolved ''; remaining name 'TMD_PERSISTENCE'
>>>>        at
>>>> weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1138)
>>>>        at
>>>> weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:251)
>>>>        at
>>>> weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:171)
>>>>        at
>>>> weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:205)
>>>>        at
>>>> weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:254)
>>>>        at
>>>> weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:367)
>>>>        at javax.naming.InitialContext.lookup(InitialContext.java:351)
>>>>        at
>>>> org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155)
>>>>        at
>>>> org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:88)
>>>>        at
>>>> org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:153)
>>>>        at
>>>> org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
>>>>
>>>> Can anybody give me a hint what i am doing wrong?
>>>>
>>>> Thanks,
>>>> Bernd Altmiks
>>>>
>>>> My Camel-Context:
>>>> ...
>>>> <jee:jndi-lookup id="eMFactory" jndi-name="TMD_PERSISTENCE"/>
>>>>
>>>> <bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent">
>>>>        <property name="entityManagerFactory" ref="eMFactory" />
>>>>        <property name="transactionManager" ref="txManager" />
>>>> </bean>
>>>>
>>>> <bean id="txManager"
>>>> class="org.springframework.transaction.jta.WebLogicJtaTransactionManager"/>
>>>> ...
>>>>
>>>>
>>>> My ejb-jar.xml
>>>>
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>
>>>> <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
>>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>>>        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
>>>> http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
>>>>        version="3.0">
>>>>        <enterprise-beans>
>>>>
>>>>                <session>
>>>>                        <ejb-name>ITMDClientDAO</ejb-name>
>>>>                        <ejb-class>tmd.al.dao.TMDClientDAO</ejb-class>
>>>>                        <session-type>Stateless</session-type>
>>>>                        <persistence-unit-ref>
>>>>
>>>>  <persistence-unit-ref-name>TMD_PERSISTENCE</persistence-unit-ref-name>
>>>>
>>>>  <persistence-unit-name>TMD_PERSISTENCE</persistence-unit-name>
>>>>
>>>>  <mapped-name>TMD_PERSISTENCE</mapped-name>
>>>>                        </persistence-unit-ref>
>>>>                </session>
>>>>        </enterprise-beans>
>>>> </ejb-jar>
>>>>
>>>>
>>>> My persistence.xml
>>>>
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>> <persistence xmlns="http://java.sun.com/xml/ns/persistence"
>>>>        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>>> version="1.0"
>>>>        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
>>>> http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
>>>>  <persistence-unit name="TMD_PERSISTENCE" transaction-type="JTA">
>>>>    <provider>org.hibernate.ejb.HibernatePersistence</provider>
>>>>
>>>> <jta-data-source>com.mummert.tributum.tbpersistence.TributumDataSource</jta-data-source>
>>>>        <class>tmd.al.entity.TMDMessage</class>
>>>>    <properties>
>>>>      <property name="hibernate.dialect"
>>>> value="org.hibernate.dialect.Oracle10gDialect"/>
>>>>      <property name="hibernate.transaction.manager_lookup_class"
>>>> value="org.hibernate.transaction.WeblogicTransactionManagerLookup" />
>>>>      <property name="hibernate.show_sql" value="false" />
>>>>      <property name="hibernate.format_sql" value="false" />
>>>>      <property name="hibernate.use_sql_comments" value="false"/>
>>>>      <property name="hibernate.generate_statistics" value="false" />
>>>>           <property
>>>> name="hibernate.jndi.weblogic.jndi.replicateBindings"
>>>> value="false" />
>>>>            <property name="hibernate.query.factory_class"
>>>> value="org.hibernate.hql.classic.ClassicQueryTranslatorFactory"/>
>>>>      <property name="hibernate.cache.use_second_level_cache"
>>>> value="false"/>
>>>>    </properties>
>>>>  </persistence-unit>
>>>> </persistence>
>>>>
>>>>
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/JPA-component-in-a-JEE5-environment%3A-EntityManagerFactory-from-JNDI-tp25219979p25219979.html
>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> Claus Ibsen
>>> Apache Camel Committer
>>>
>>> Open Source Integration: http://fusesource.com
>>> Blog: http://davsclaus.blogspot.com/
>>> Twitter: http://twitter.com/davsclaus
>>>
>>>
>>
>>
>
> Doesn't work on Weblogic. There is no way to get the EntityManager from
> JNDI. Here is the answer from the Oracle-Support:
>
> "According the EJB3 specification, you need to lookup the entity from the
> same container (from any servlet or session bean running on that
> container)."
>

And how do Oracle Support envision you should lookup an Entity?
Using JNDI? And if so how do you do that? How do you configure / setup this?
And how do you get the Entity registered in the first place?



>
> --
> View this message in context: http://www.nabble.com/JPA-component-in-a-JEE5-environment%3A-EntityManagerFactory-from-JNDI-tp25219979p26056419.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



--
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: JPA component in a JEE5 environment: EntityManagerFactory from JNDI

by B_A :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Claus Ibsen-2 wrote:
On Mon, Oct 26, 2009 at 10:13 AM, BAltmiks
<bernd.altmiks@steria-mummert.de> wrote:
>
>
>
> BAltmiks wrote:
>>
>> Hi Claus,
>>
>> this is what the Oracle-Support says. I will try these.
>>
>>
>> Hello Bernd,
>>
>> I tried calling you regarding the issue, however couldn't reach.
>>
>> As per the issue I understand that you are using trying to lookup the
>> Entity Manager instance and you are trying to use Entity Manager
>> Factory, but you do not wish to use injection of .@PersistenceContext.
>>
>> Please let me know if you are using any JPA provider (e.g. kodo,
>> hibernate etc).
>>
>> In JEE the EntityManager or EntityManagerFactory can either be looked
>> up in JNDI, or injected into a SessionBean. To look up the
>> EntityManager in JNDI it must be published in JNDI such as through a
>> <persistence-context-ref> in a SessionBean's ejb-jar.xml file. To
>> inject an EntityManager or EntityManagerFactory the
>> annotation .@PersistenceContext or .@PersistenceUnit are used.
>>
>> For your reference I am adding both the options (annotation / non-
>> annota)
>>
>> Example SessionBean ejb-jar.xml file with persistence context
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
>> http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
>> version="3.0">
>> <enterprise-beans>
>> <session>
>> <ejb-name>EmployeeService</ejb-name>
>> <business-remote>org.acme.EmployeeService</business-remote>
>> <ejb-class>org.acme.EmployeeServiceBean</ejb-class>
>> <session-type>Stateless</session-type>
>> <persistence-context-ref>
>> <persistence-context-ref-name>persistence/acme/entity-manager</
>> persistence-context-ref-name>
>> <persistence-unit-name>acme</persistence-unit-name>
>> </persistence-context-ref>
>> <persistence-unit-ref>
>> <persistence-unit-ref-name>persistence/acme/factory</persistence-unit-
>> ref-name>
>> <persistence-unit-name>acme</persistence-unit-name>
>> </persistence-unit-ref>
>> </session>
>> </enterprise-beans>
>> </ejb-jar>
>>
>> Example of looking up an EntityManager in JNDI
>> ===============================================
>>
>> InitialContext context = new InitialContext();
>> EntityManager entityManager = (EntityManager)context.lookup("java:comp/
>> env/persistence/acme/entity-manager");
>> ...
>>
>> Example of looking up an EntityManagerFactory in JNDI
>> =====================================================
>>
>> InitialContext context = new InitialContext();
>> EntityManagerFactory factory = (EntityManagerFactory)context.lookup
>> ("java:comp/env/persistence/acme/factory");
>> ...
>>
>> Example of injecting an EntityManager and EntityManagerFactory
>> ===============================================================
>>
>> .@Stateless(name="EmployeeService", mappedName="acme/EmployeeService")
>> .@Remote(EmployeeService.class)
>> public class EmployeeServiceBean implements EmployeeService {
>>
>> .@PersistenceContext(unitName="acme")
>> private EntityManager entityManager;
>>
>> .@PersistenceUnit(unitName="acme")
>> private EntityManagerFactory factory;
>> ...
>> }
>>
>> Please feel free to get back to me in case of any doubt or query
>> regarding the same.
>>
>>
>> Regards,
>> Saumajit Das
>>
>>
>>
>>
>>
>>>
>> Claus Ibsen-2 wrote:
>>>
>>>>Hi
>>>>
>>>>That is the same s*** with the J2ee servers and the JNDI lookup. Its
>>>>painful when it does not work and you need to setup all kind
>>>>of indirections in various deployment descriptors both standard j2ee
>>>>related and server specific.
>>>>
>>>>I will try googling and look at WebLogic documentation as its a pure
>>>>WebLogic + Spring J2ee lookup thingy.
>>>
>>>
>>>
>>> On Mon, Aug 31, 2009 at 10:31 AM,
>>> BAltmiks<bernd.altmiks@steria-mummert.de> wrote:
>>>>
>>>> - Camel 2.0M3
>>>> - Camel-JPA 2.0M3
>>>> - Weblogic 10
>>>> - Hibernate-Core 3.3.0.SP1
>>>> - Hibernate-EntityManager 3.4.0.GA
>>>> - Configuration in Spring XML
>>>>
>>>>
>>>> Hi,
>>>>
>>>> I tried to make use of the jpa component. But I have problems to get an
>>>> EntityManagerFactory from JNDI on Weblogic 10. As described in the
>>>> http://static.springsource.org/spring/docs/2.5.x/reference/orm.html#orm-jpa
>>>> Spring JPA Documentation  I do a JNDI-Lookup. persistence-unit-ref
>>>> entries
>>>> are defined in the Java EE deployment descriptor (ejb-jar.xml).
>>>>
>>>> The Exception is:
>>>>
>>>> javax.naming.NameNotFoundException: Unable to resolve 'TMD_PERSISTENCE'.
>>>> Resolved ''; remaining name 'TMD_PERSISTENCE'
>>>>        at
>>>> weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1138)
>>>>        at
>>>> weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:251)
>>>>        at
>>>> weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:171)
>>>>        at
>>>> weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:205)
>>>>        at
>>>> weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:254)
>>>>        at
>>>> weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:367)
>>>>        at javax.naming.InitialContext.lookup(InitialContext.java:351)
>>>>        at
>>>> org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155)
>>>>        at
>>>> org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:88)
>>>>        at
>>>> org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:153)
>>>>        at
>>>> org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
>>>>
>>>> Can anybody give me a hint what i am doing wrong?
>>>>
>>>> Thanks,
>>>> Bernd Altmiks
>>>>
>>>> My Camel-Context:
>>>> ...
>>>> <jee:jndi-lookup id="eMFactory" jndi-name="TMD_PERSISTENCE"/>
>>>>
>>>> <bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent">
>>>>        <property name="entityManagerFactory" ref="eMFactory" />
>>>>        <property name="transactionManager" ref="txManager" />
>>>> </bean>
>>>>
>>>> <bean id="txManager"
>>>> class="org.springframework.transaction.jta.WebLogicJtaTransactionManager"/>
>>>> ...
>>>>
>>>>
>>>> My ejb-jar.xml
>>>>
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>
>>>> <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
>>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>>>        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
>>>> http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
>>>>        version="3.0">
>>>>        <enterprise-beans>
>>>>
>>>>                <session>
>>>>                        <ejb-name>ITMDClientDAO</ejb-name>
>>>>                        <ejb-class>tmd.al.dao.TMDClientDAO</ejb-class>
>>>>                        <session-type>Stateless</session-type>
>>>>                        <persistence-unit-ref>
>>>>
>>>>  <persistence-unit-ref-name>TMD_PERSISTENCE</persistence-unit-ref-name>
>>>>
>>>>  <persistence-unit-name>TMD_PERSISTENCE</persistence-unit-name>
>>>>
>>>>  <mapped-name>TMD_PERSISTENCE</mapped-name>
>>>>                        </persistence-unit-ref>
>>>>                </session>
>>>>        </enterprise-beans>
>>>> </ejb-jar>
>>>>
>>>>
>>>> My persistence.xml
>>>>
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>> <persistence xmlns="http://java.sun.com/xml/ns/persistence"
>>>>        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>>> version="1.0"
>>>>        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
>>>> http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
>>>>  <persistence-unit name="TMD_PERSISTENCE" transaction-type="JTA">
>>>>    <provider>org.hibernate.ejb.HibernatePersistence</provider>
>>>>
>>>> <jta-data-source>com.mummert.tributum.tbpersistence.TributumDataSource</jta-data-source>
>>>>        <class>tmd.al.entity.TMDMessage</class>
>>>>    <properties>
>>>>      <property name="hibernate.dialect"
>>>> value="org.hibernate.dialect.Oracle10gDialect"/>
>>>>      <property name="hibernate.transaction.manager_lookup_class"
>>>> value="org.hibernate.transaction.WeblogicTransactionManagerLookup" />
>>>>      <property name="hibernate.show_sql" value="false" />
>>>>      <property name="hibernate.format_sql" value="false" />
>>>>      <property name="hibernate.use_sql_comments" value="false"/>
>>>>      <property name="hibernate.generate_statistics" value="false" />
>>>>           <property
>>>> name="hibernate.jndi.weblogic.jndi.replicateBindings"
>>>> value="false" />
>>>>            <property name="hibernate.query.factory_class"
>>>> value="org.hibernate.hql.classic.ClassicQueryTranslatorFactory"/>
>>>>      <property name="hibernate.cache.use_second_level_cache"
>>>> value="false"/>
>>>>    </properties>
>>>>  </persistence-unit>
>>>> </persistence>
>>>>
>>>>
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/JPA-component-in-a-JEE5-environment%3A-EntityManagerFactory-from-JNDI-tp25219979p25219979.html
>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> Claus Ibsen
>>> Apache Camel Committer
>>>
>>> Open Source Integration: http://fusesource.com
>>> Blog: http://davsclaus.blogspot.com/
>>> Twitter: http://twitter.com/davsclaus
>>>
>>>
>>
>>
>
> Doesn't work on Weblogic. There is no way to get the EntityManager from
> JNDI. Here is the answer from the Oracle-Support:
>
> "According the EJB3 specification, you need to lookup the entity from the
> same container (from any servlet or session bean running on that
> container)."
>

And how do Oracle Support envision you should lookup an Entity?
Using JNDI? And if so how do you do that? How do you configure / setup this?
And how do you get the Entity registered in the first place?



>
> --
> View this message in context: http://www.nabble.com/JPA-component-in-a-JEE5-environment%3A-EntityManagerFactory-from-JNDI-tp25219979p26056419.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



--
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
>And how do Oracle Support envision you should lookup an Entity?
>Using JNDI? And if so how do you do that? How do you configure / setup this?
>And how do you get the Entity registered in the first place?

Sorry Claus my mistake when I wrote this Message. I mean EntityManagerFactory and not Entity. I

have corrected my Message.

I have sent the Oracle-Support an example Testcase  so that they can see what i

want to do. I my case lookup the EntityManagerFactory from an "client". An POJO like

Camel/Spring. The answer I got was that it is not possible on Weblogic 10.0 if you are not

"inside" an Session Bean or Servlet.

At the Moment, as a workaround, I use an Stateless Session Bean where the EntityManager (not the

EntityManagerFactory) gets injected to persist my Entity with Camel.  

I would be thankfully if you have any further suggestions.

Regards,
Bernd



Re: JPA component in a JEE5 environment: EntityManagerFactory from JNDI

by Claus Ibsen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi

There is an setter on JpaComponent

    public void setEntityManagerFactory(EntityManagerFactory
entityManagerFactory) {

So see the section - configuring entity manager factory at
http://camel.apache.org/jpa

And have that EntityManagerFactory looked up in JNDI.
Spring have some jndi lookup thingy you can use to lookup name it with
an id you can refer to from that camel jpa component.


On Mon, Oct 26, 2009 at 1:00 PM, B_A <bernd.altmiks@...> wrote:

>
>
> Claus Ibsen-2 wrote:
>>
>> On Mon, Oct 26, 2009 at 10:13 AM, BAltmiks
>> <bernd.altmiks@...> wrote:
>>>
>>>
>>>
>>> BAltmiks wrote:
>>>>
>>>> Hi Claus,
>>>>
>>>> this is what the Oracle-Support says. I will try these.
>>>>
>>>>
>>>> Hello Bernd,
>>>>
>>>> I tried calling you regarding the issue, however couldn't reach.
>>>>
>>>> As per the issue I understand that you are using trying to lookup the
>>>> Entity Manager instance and you are trying to use Entity Manager
>>>> Factory, but you do not wish to use injection of .@PersistenceContext.
>>>>
>>>> Please let me know if you are using any JPA provider (e.g. kodo,
>>>> hibernate etc).
>>>>
>>>> In JEE the EntityManager or EntityManagerFactory can either be looked
>>>> up in JNDI, or injected into a SessionBean. To look up the
>>>> EntityManager in JNDI it must be published in JNDI such as through a
>>>> <persistence-context-ref> in a SessionBean's ejb-jar.xml file. To
>>>> inject an EntityManager or EntityManagerFactory the
>>>> annotation .@PersistenceContext or .@PersistenceUnit are used.
>>>>
>>>> For your reference I am adding both the options (annotation / non-
>>>> annota)
>>>>
>>>> Example SessionBean ejb-jar.xml file with persistence context
>>>>
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>> <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
>>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>>> xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
>>>> http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
>>>> version="3.0">
>>>> <enterprise-beans>
>>>> <session>
>>>> <ejb-name>EmployeeService</ejb-name>
>>>> <business-remote>org.acme.EmployeeService</business-remote>
>>>> <ejb-class>org.acme.EmployeeServiceBean</ejb-class>
>>>> <session-type>Stateless</session-type>
>>>> <persistence-context-ref>
>>>> <persistence-context-ref-name>persistence/acme/entity-manager</
>>>> persistence-context-ref-name>
>>>> <persistence-unit-name>acme</persistence-unit-name>
>>>> </persistence-context-ref>
>>>> <persistence-unit-ref>
>>>> <persistence-unit-ref-name>persistence/acme/factory</persistence-unit-
>>>> ref-name>
>>>> <persistence-unit-name>acme</persistence-unit-name>
>>>> </persistence-unit-ref>
>>>> </session>
>>>> </enterprise-beans>
>>>> </ejb-jar>
>>>>
>>>> Example of looking up an EntityManager in JNDI
>>>> ===============================================
>>>>
>>>> InitialContext context = new InitialContext();
>>>> EntityManager entityManager = (EntityManager)context.lookup("java:comp/
>>>> env/persistence/acme/entity-manager");
>>>> ...
>>>>
>>>> Example of looking up an EntityManagerFactory in JNDI
>>>> =====================================================
>>>>
>>>> InitialContext context = new InitialContext();
>>>> EntityManagerFactory factory = (EntityManagerFactory)context.lookup
>>>> ("java:comp/env/persistence/acme/factory");
>>>> ...
>>>>
>>>> Example of injecting an EntityManager and EntityManagerFactory
>>>> ===============================================================
>>>>
>>>> .@Stateless(name="EmployeeService", mappedName="acme/EmployeeService")
>>>> .@Remote(EmployeeService.class)
>>>> public class EmployeeServiceBean implements EmployeeService {
>>>>
>>>> .@PersistenceContext(unitName="acme")
>>>> private EntityManager entityManager;
>>>>
>>>> .@PersistenceUnit(unitName="acme")
>>>> private EntityManagerFactory factory;
>>>> ...
>>>> }
>>>>
>>>> Please feel free to get back to me in case of any doubt or query
>>>> regarding the same.
>>>>
>>>>
>>>> Regards,
>>>> Saumajit Das
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>>
>>>> Claus Ibsen-2 wrote:
>>>>>
>>>>>>Hi
>>>>>>
>>>>>>That is the same s*** with the J2ee servers and the JNDI lookup. Its
>>>>>>painful when it does not work and you need to setup all kind
>>>>>>of indirections in various deployment descriptors both standard j2ee
>>>>>>related and server specific.
>>>>>>
>>>>>>I will try googling and look at WebLogic documentation as its a pure
>>>>>>WebLogic + Spring J2ee lookup thingy.
>>>>>
>>>>>
>>>>>
>>>>> On Mon, Aug 31, 2009 at 10:31 AM,
>>>>> BAltmiks<bernd.altmiks@...> wrote:
>>>>>>
>>>>>> - Camel 2.0M3
>>>>>> - Camel-JPA 2.0M3
>>>>>> - Weblogic 10
>>>>>> - Hibernate-Core 3.3.0.SP1
>>>>>> - Hibernate-EntityManager 3.4.0.GA
>>>>>> - Configuration in Spring XML
>>>>>>
>>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> I tried to make use of the jpa component. But I have problems to get
>>>>>> an
>>>>>> EntityManagerFactory from JNDI on Weblogic 10. As described in the
>>>>>> http://static.springsource.org/spring/docs/2.5.x/reference/orm.html#orm-jpa
>>>>>> Spring JPA Documentation  I do a JNDI-Lookup. persistence-unit-ref
>>>>>> entries
>>>>>> are defined in the Java EE deployment descriptor (ejb-jar.xml).
>>>>>>
>>>>>> The Exception is:
>>>>>>
>>>>>> javax.naming.NameNotFoundException: Unable to resolve
>>>>>> 'TMD_PERSISTENCE'.
>>>>>> Resolved ''; remaining name 'TMD_PERSISTENCE'
>>>>>>        at
>>>>>> weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1138)
>>>>>>        at
>>>>>> weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:251)
>>>>>>        at
>>>>>> weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:171)
>>>>>>        at
>>>>>> weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:205)
>>>>>>        at
>>>>>> weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:254)
>>>>>>        at
>>>>>> weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:367)
>>>>>>        at javax.naming.InitialContext.lookup(InitialContext.java:351)
>>>>>>        at
>>>>>> org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155)
>>>>>>        at
>>>>>> org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:88)
>>>>>>        at
>>>>>> org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:153)
>>>>>>        at
>>>>>> org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
>>>>>>
>>>>>> Can anybody give me a hint what i am doing wrong?
>>>>>>
>>>>>> Thanks,
>>>>>> Bernd Altmiks
>>>>>>
>>>>>> My Camel-Context:
>>>>>> ...
>>>>>> <jee:jndi-lookup id="eMFactory" jndi-name="TMD_PERSISTENCE"/>
>>>>>>
>>>>>> <bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent">
>>>>>>        <property name="entityManagerFactory" ref="eMFactory" />
>>>>>>        <property name="transactionManager" ref="txManager" />
>>>>>> </bean>
>>>>>>
>>>>>> <bean id="txManager"
>>>>>> class="org.springframework.transaction.jta.WebLogicJtaTransactionManager"/>
>>>>>> ...
>>>>>>
>>>>>>
>>>>>> My ejb-jar.xml
>>>>>>
>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>>
>>>>>> <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
>>>>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>>>>>        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
>>>>>> http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
>>>>>>        version="3.0">
>>>>>>        <enterprise-beans>
>>>>>>
>>>>>>                <session>
>>>>>>                        <ejb-name>ITMDClientDAO</ejb-name>
>>>>>>                        <ejb-class>tmd.al.dao.TMDClientDAO</ejb-class>
>>>>>>                        <session-type>Stateless</session-type>
>>>>>>                        <persistence-unit-ref>
>>>>>>
>>>>>>  <persistence-unit-ref-name>TMD_PERSISTENCE</persistence-unit-ref-name>
>>>>>>
>>>>>>  <persistence-unit-name>TMD_PERSISTENCE</persistence-unit-name>
>>>>>>
>>>>>>  <mapped-name>TMD_PERSISTENCE</mapped-name>
>>>>>>                        </persistence-unit-ref>
>>>>>>                </session>
>>>>>>        </enterprise-beans>
>>>>>> </ejb-jar>
>>>>>>
>>>>>>
>>>>>> My persistence.xml
>>>>>>
>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>> <persistence xmlns="http://java.sun.com/xml/ns/persistence"
>>>>>>        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>>>>> version="1.0"
>>>>>>        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
>>>>>> http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
>>>>>>  <persistence-unit name="TMD_PERSISTENCE" transaction-type="JTA">
>>>>>>    <provider>org.hibernate.ejb.HibernatePersistence</provider>
>>>>>>
>>>>>> <jta-data-source>com.mummert.tributum.tbpersistence.TributumDataSource</jta-data-source>
>>>>>>        <class>tmd.al.entity.TMDMessage</class>
>>>>>>    <properties>
>>>>>>      <property name="hibernate.dialect"
>>>>>> value="org.hibernate.dialect.Oracle10gDialect"/>
>>>>>>      <property name="hibernate.transaction.manager_lookup_class"
>>>>>> value="org.hibernate.transaction.WeblogicTransactionManagerLookup" />
>>>>>>      <property name="hibernate.show_sql" value="false" />
>>>>>>      <property name="hibernate.format_sql" value="false" />
>>>>>>      <property name="hibernate.use_sql_comments" value="false"/>
>>>>>>      <property name="hibernate.generate_statistics" value="false" />
>>>>>>           <property
>>>>>> name="hibernate.jndi.weblogic.jndi.replicateBindings"
>>>>>> value="false" />
>>>>>>            <property name="hibernate.query.factory_class"
>>>>>> value="org.hibernate.hql.classic.ClassicQueryTranslatorFactory"/>
>>>>>>      <property name="hibernate.cache.use_second_level_cache"
>>>>>> value="false"/>
>>>>>>    </properties>
>>>>>>  </persistence-unit>
>>>>>> </persistence>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> View this message in context:
>>>>>> http://www.nabble.com/JPA-component-in-a-JEE5-environment%3A-EntityManagerFactory-from-JNDI-tp25219979p25219979.html
>>>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Claus Ibsen
>>>>> Apache Camel Committer
>>>>>
>>>>> Open Source Integration: http://fusesource.com
>>>>> Blog: http://davsclaus.blogspot.com/
>>>>> Twitter: http://twitter.com/davsclaus
>>>>>
>>>>>
>>>>
>>>>
>>>
>>> Doesn't work on Weblogic. There is no way to get the EntityManager from
>>> JNDI. Here is the answer from the Oracle-Support:
>>>
>>> "According the EJB3 specification, you need to lookup the entity from the
>>> same container (from any servlet or session bean running on that
>>> container)."
>>>
>>
>> And how do Oracle Support envision you should lookup an Entity?
>> Using JNDI? And if so how do you do that? How do you configure / setup
>> this?
>> And how do you get the Entity registered in the first place?
>>
>>
>>
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/JPA-component-in-a-JEE5-environment%3A-EntityManagerFactory-from-JNDI-tp25219979p26056419.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>>
>> --
>> Claus Ibsen
>> Apache Camel Committer
>>
>> Author of Camel in Action: http://www.manning.com/ibsen/
>> Open Source Integration: http://fusesource.com
>> Blog: http://davsclaus.blogspot.com/
>> Twitter: http://twitter.com/davsclaus
>>
>>
>
>>And how do Oracle Support envision you should lookup an Entity?
>>Using JNDI? And if so how do you do that? How do you configure / setup
> this?
>>And how do you get the Entity registered in the first place?
>
> Sorry Claus my mistake when I wrote this Message. I mean
> EntityManagerFactory and not Entity. I
> http://www.nabble.com/file/p26058442/entitymanagerfactorylookup.zip
> entitymanagerfactorylookup.zip
> http://www.nabble.com/file/p26058442/entitymanagerfactorylookup.zip
> entitymanagerfactorylookup.zip
> have corrected my Message.
>
> I have sent the Oracle-Support an example Testcase (find it attached) so
> that they can see what i
>
> want to do. I my case lookup the EntityManagerFactory from an "client". An
> POJO like
>
> Camel/Spring. The answer I got was that it is not possible on Weblogic 10.0
> if you are not
>
> "inside" an Session Bean or Servlet.
>
> At the Moment, as a workaround, I use an Stateless Session Bean where the
> EntityManager (not the
>
> EntityManagerFactory) gets injected to persist my Entity with Camel.
>
> I would be thankfully if you have any further suggestions.
>
> Regards,
> Bernd
>
> --
> View this message in context: http://www.nabble.com/JPA-component-in-a-JEE5-environment%3A-EntityManagerFactory-from-JNDI-tp25219979p26058442.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



--
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus