Hibernate Tools: Error parsing JNDI name
Asked Answered
I

2

18

We are trying to upgrade from Hibernate 3.6.7 to 4.1.2 and Hibernate Tools 3.2.0 to 3.5.0

We generate a DB creation script using Ant:

     <hibernatetool destdir="${target}">
        <jpaconfiguration persistenceunit="stdcmpOrderPersistenceUnit" propertyfile="@{propertyfile}"/>
        <classpath refid="@{classpathid}"/>
        <!-- the file name is relative to $destdir -->
        <hbm2ddl outputfilename="@{output}" format="true" export="false" drop="false"/>
     </hibernatetool>

Our persistence unit look like this:

<persistence-unit name="stdcmpOrderPersistenceUnit" transaction-type="JTA">

    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>jdbc/lakshmi_stdcmp</jta-data-source>
    <mapping-file>META-INF/stdcmpOrderNamedQueries.xml</mapping-file>

    <class>ch.ethz.id.wai.lakshmi.stdcmp.persistency.PersistentOrder</class>

    <exclude-unlisted-classes>true</exclude-unlisted-classes>

    <properties>
        <property name="hibernate.show_sql" value="false"/>
        <property name="hibernate.format_sql" value="false"/>
    </properties>

</persistence-unit>

After the upgrade we get the following error:

[hibernatetool] org.hibernate.service.jndi.JndiException: Error parsing JNDI name [jdbc/lakshmi_stdcmp]
[hibernatetool] javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial

Why does Hibernate try to resolve the JNDI name since all the information on the PersistenceUnit is available? We had no problems with the old version.

And in any case how can we specify a NamingFactory? (and which one?)

Impetigo answered 11/5, 2012 at 13:31 Comment(0)
C
3

The problem is from your hibernate tool, you have configured the hibernate tool to use persistence unit which has a jta data-source configured via JNDI. In order for the ant task to talk to JNDI it needs naming factory url and provider. Use the naming factory class of your application server where the datasource is configured.

Hope it helps.

Continuum answered 6/11, 2012 at 17:9 Comment(0)
C
62

I was having a similar problem, specifically causing the "Error parsing JNDI name", and it was easily fixed by simply removing the empty name attribute from the session-factory tag.

My hibernate.cfg.xml had

<session-factory name="">

This was auto-generated, so I just removed the name attrib.

This fix was found here: https://forum.hibernate.org/viewtopic.php?f=1&t=1014760

Colet answered 6/11, 2012 at 16:5 Comment(2)
Any idea why does hibernate not like that?Lonesome
@webber: As Leandro said: This cnf File was autogenerated by hibernate reveng. We simply forgot to give a proper session name, when creating the config file.Tullius
C
3

The problem is from your hibernate tool, you have configured the hibernate tool to use persistence unit which has a jta data-source configured via JNDI. In order for the ant task to talk to JNDI it needs naming factory url and provider. Use the naming factory class of your application server where the datasource is configured.

Hope it helps.

Continuum answered 6/11, 2012 at 17:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.