Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Generate Tables from Entities results in NoInitialContextException
Generate Tables from Entities results in NoInitialContextException [message #1044132] Thu, 18 April 2013 14:29 Go to next message
Benedikt Erdmann is currently offline Benedikt ErdmannFriend
Messages: 6
Registered: November 2012
Junior Member
When I try to generate Database Tables from my project's Entities the Exception below is thrown.

If I understand correctly, the Exception suggested to specify java.naming.factory.initial:
So I went through several parts of JBoss and Eclipselink-Documentation, not quite sure what I was looking for, did experiments with a jndi.properties-file and realized in the end that I am absolutely clueless.

BTW: The generation of Entities from Tables (so the other way round) works without problems.

Writing this post I got the Message "You can only use links to eclipse.org sites while you have fewer than 5 messages." so I had to put an "X" into the "http"s

[EL Info]: EclipseLink, version: Eclipse Persistence Services - 2.3.2.v20111125-r10461
[EL Severe]: Local Exception Stack: 
Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [java:jboss/datasources/MySQLDS].
Internal Exception: 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
    at org.eclipse.persistence.exceptions.ValidationException.cannotAcquireDataSource(ValidationException.java:497)
    at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:109)
    at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:584)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:206)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:488)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getDatabaseSession(EntityManagerFactoryDelegate.java:188)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:277)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:294)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:272)
    at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.perform(Main.java:85)
    at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.execute(Main.java:76)
    at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.main(Main.java:63)
Caused by: 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
    at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
    at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
    at javax.naming.InitialContext.lookup(Unknown Source)
    at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:103)
    ... 11 more

Exception in thread "main" javax.persistence.PersistenceException: Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [java:jboss/datasources/MySQLDS].
Internal Exception: 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
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:517)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getDatabaseSession(EntityManagerFactoryDelegate.java:188)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:277)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:294)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:272)
    at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.perform(Main.java:85)
    at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.execute(Main.java:76)
    at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.main(Main.java:63)
Caused by: Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [java:jboss/datasources/MySQLDS].
Internal Exception: 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
    at org.eclipse.persistence.exceptions.ValidationException.cannotAcquireDataSource(ValidationException.java:497)
    at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:109)
    at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:584)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:206)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:488)
    ... 7 more
Caused by: 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
    at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
    at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
    at javax.naming.InitialContext.lookup(Unknown Source)
    at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:103)
    ... 11 more

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

<persistence version="2.0"
    xmlns="htXtp://java.sun.com/xml/ns/persistence" xmlns:xsi="htXtp://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="htXtp://java.sun.com/xml/ns/persistence htXtp://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="DynamicWebProject" transaction-type="JTA">
  <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>java:jboss/datasources/MySQLDS</jta-data-source>
    <properties>
      <!-- <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> -->
      <property name="javax.persistence.jtaDataSource" value="java:jboss/datasources/MySQLDS" />
    </properties>
  </persistence-unit>
</persistence>

[Updated on: Thu, 18 April 2013 14:37]

Report message to a moderator

Re: Generate Tables from Entities results in NoInitialContextException [message #1044279 is a reply to message #1044132] Thu, 18 April 2013 17:59 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
This was discussed on a stack overflow post here http://stackoverflow.com/questions/16058743/generate-tables-from-entities-results-in-noinitialcontextexception, I assume it is the same issue. The problem is your entity->Table creation uses the persistence.xml, which is configured to run within JBoss. If you use the eclipselink.ddl-generation property within the file and deploy to JBoss, and have the MySQLDS datasource setup there correctly, you should see the tables get created correctly. These settings will not work outside of JBoss - you must use the jdbc url properties outside of a container.

Best Regards,
Chris
Re: Generate Tables from Entities results in NoInitialContextException [message #1044306 is a reply to message #1044279] Thu, 18 April 2013 18:46 Go to previous messageGo to next message
Benedikt Erdmann is currently offline Benedikt ErdmannFriend
Messages: 6
Registered: November 2012
Junior Member
Hey Chris,
that question on stackoverflow was actually mine and I followed your instructions and it did not work.
But maybe I misunderstood:
1. I simply uncomment <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> in persistence.xml
2. I "full publish" the project in eclipse server tab
3. I start the server
4. I ping the datasource (success), check my web application with all the stuff from the database (success)
5. And then I hit "generate tables from entities", choose database as output mode and get the above exception stack
Did I miss something?

When I watch Eclipse's Data Source Explorer when hitting "generate tables from entities" the Datasource looks just for this tiny moment disconnected (it does indeed look different)

[Updated on: Thu, 18 April 2013 18:56]

Report message to a moderator

Re: Generate Tables from Entities results in NoInitialContextException [message #1044895 is a reply to message #1044306] Fri, 19 April 2013 13:25 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Yes, the settings you have can only be used within the server, they cannot be used from within Eclipse as there is no way to get the datasource. The application needs to be deployed and accessed, which will cause the tables to be created.
Re: Generate Tables from Entities results in NoInitialContextException [message #1045018 is a reply to message #1044895] Fri, 19 April 2013 16:47 Go to previous message
Benedikt Erdmann is currently offline Benedikt ErdmannFriend
Messages: 6
Registered: November 2012
Junior Member
So the way I decribed it - running the server in Eclipse - does not work? Where is the difference?
I have to run the server outside eclipse?

Good news: This time the JPA Tools-Command "generate tables from entities" in Eclipse did work. Bad news: I messed up and forgot to enter the actual values. jdbc.url, user and password aren't actual values - I don't get how this works. My persistence.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>

<persistence version="2.0"
    xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

  <persistence-unit name="DynamicWebProject" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="eclipselink.target-database" value="MySQL"/>
      <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/hoho;create=true"/>
      <property name="javax.persistence.jdbc.user" value="user"/>
      <property name="javax.persistence.jdbc.password" value="password"/>
    </properties>
  </persistence-unit>
</persistence>


Why did this work?

[Updated on: Fri, 19 April 2013 16:49]

Report message to a moderator

Previous Topic:DBWS / NamingConventionTransformer
Next Topic:Predeployment failing on EclipseLink 2.3.2
Goto Forum:
  


Current Time: Tue Apr 23 17:06:44 GMT 2024

Powered by FUDForum. Page generated in 0.03163 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top