- This topic has 5 replies, 2 voices, and was last updated 18 years, 4 months ago by Haris Peco.
-
AuthorPosts
-
James CaryMemberHi,
I’ve been trying to use the generate DAO function when creating hibernte mappings. I have a jndi datasource in JBOSS
called java:musicDS. When I try to generate the mappings, I get the following stacktrace in my workspace/.metadata/.log file:
<log>
[jamesc@snoopy .metadata]$ tail -750 .log
!ENTRY org.hibernate.eclipse 4 40000 2006-06-17 12:22:15.848
!MESSAGE ERROR Worker-4 org.hibernate.util.NamingHelper – Could not obtain initial context
!STACK 0
javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:652)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.init(InitialContext.java:219)
at javax.naming.InitialContext.<init>(InitialContext.java:195)
at org.hibernate.util.NamingHelper.getInitialContext(NamingHelper.java:28)
at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:366)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:60)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1855)
at com.genuitec.eclipse.hibernate.wizards.MEJDBCMetaDataConfiguration.readFromJDBC(MEJDBCMetaDataConfiguration.java:68)
at com.genuitec.eclipse.hibernate.wizards.GenerateArtifactsJob$5.execute(GenerateArtifactsJob.java:393)
at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:35)
at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:68)
at com.genuitec.eclipse.hibernate.wizards.GenerateArtifactsJob.buildConfiguration(GenerateArtifactsJob.java:388)
at com.genuitec.eclipse.hibernate.wizards.GenerateArtifactsJob.run(GenerateArtifactsJob.java:255)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:76)
Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:219)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:649)
… 17 more!ENTRY org.hibernate.eclipse 4 50000 2006-06-17 12:22:15.851
!MESSAGE FATAL Worker-4 org.hibernate.connection.DatasourceConnectionProvider – Could not find datasource: java:musicDB
!STACK 0
…
</log>I’ve tried adding jnpserver.jar to my classpath, as well as jboss-client.jar, jbossall-client.jar and jboss-common-client.jar, but none seems to solve the problem.
My hibernate.cfg.xml file looks like this:
<session-factory>
<property name=”connection.username”>music</property>
<property name=”dialect”>org.hibernate.dialect.Oracle9Dialect</property>
<property name=”jndi.url”>jnp://localhost:1099</property>
<property name=”jndi.class”>org.jnp.interfaces.NamingContextFactory</property>
<property name=”connection.datasource”>java:musicDB</property>
<property name=”connection.password”>password</property>
</session-factory>I’ve tried the following connection.datasource values:
java:musicDB
java:/env/jdbc/musicDB
java:/musicDB
java:env/jdbc/musicDB
java:/jdbc/musicDB
java:jdbc/musicDBall to no avail.
below is the jboss logs in which the datasource is bound, so I’d tend to believe it’s bound correctly at java:musicDB.
Any suggestions?(from the JBoss log file)
11:01:02,468 INFO [ConnectionFactoryBindingService] Bound ConnectionManager ‘jb oss.jca:name=musicDS,service=DataSourceBinding’ to JNDI name ‘java:musicDS’
Haris PecoMemberJames,
Please, can you try remove line
<property name="jndi.class">org.jnp.interfaces.NamingContextFactory</property>
and set jndi name as :
java:/comp/env/jdbc/musicDB
or
java:/comp/env/musicDB
I don’t sure if it’s error that your jndi is java:musicDB and if it’s correct then you have to use
java:/comp/env/musicDB
Best regards
James CaryMemberWhen I remove the line suggested, I get the following:
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.initialI did find one error in my JNDI datasource that was preventing it from being used outside of the VM, which I have corrected.
However, I’m still getting similar errors trying to access it from the Generate Hibernate Mapping wizzard.
This test code connects to it fine, from within the same project:
public static void main(String[] a){
Properties prop = new Properties();
prop.put(“java.naming.factory.initial”,”org.jnp.interfaces.NamingContextFactory”);
prop.put(“java.naming.provider.url”,”jnp://localhost:1099″);
prop.put(“java.naming.factory.url.pkgs”,”org.jboss.naming:org.jnp.interfaces”);
try {
Context context = new InitialContext(prop);
DataSource source = (DataSource) context.lookup(“musicDS”);
System.out.println(“context == ” + context.toString());
System.out.println(“source == ” + source.toString());
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}after correcting, I’ve tried all suggested names (java:/comp/env/jdbc/musicDS and java:/comp/env/musicDS) as well as java:musicDS, java:/musicDS and the one that wroked in the stand alone code (musicDS) but keep getting:
javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:652)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.init(InitialContext.java:219)
at javax.naming.InitialContext.<init>(InitialContext.java:195)
at org.hibernate.util.NamingHelper.getInitialContext(NamingHelper.java:28)
at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:366)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:60)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1855)
at com.genuitec.eclipse.hibernate.wizards.MEJDBCMetaDataConfiguration.readFromJDBC(MEJDBCMetaDataConfiguration.java:68)
at com.genuitec.eclipse.hibernate.wizards.GenerateArtifactsJob$5.execute(GenerateArtifactsJob.java:393)
at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:35)
at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:68)
at com.genuitec.eclipse.hibernate.wizards.GenerateArtifactsJob.buildConfiguration(GenerateArtifactsJob.java:388)
at com.genuitec.eclipse.hibernate.wizards.GenerateArtifactsJob.run(GenerateArtifactsJob.java:255)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:76)
Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:219)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:649)
… 17 moreI’m thinking it almost has to be something with my classpath in the project, but don’t know what it could be.
any more ideas?
Haris PecoMemberJames,
There is example from hibernate documentation for an application server provided JNDI datasource :
hibernate.connection.datasource = java:/comp/env/MusicDB
hibernate.transaction.factory_class = \
org.hibernate.transaction.JTATransactionFactory
hibernate.transaction.manager_lookup_class = \
org.hibernate.transaction.JBossTransactionManagerLookup
hibernate.dialect = org.hibernate.dialect.Oracle9DialectYou can’t try your old example, but you can’t add jnpserver.jar to your classpath, because MyEclipse mapping engine use eclipse classpath and doesn’t see your classpath.We will discuss that add project’s classpath in mapping, but for now you can try add jnpserver.jar to driver profile (like jdbc jar) – MyEclipse will add all jars from drivers to mapping engine.
Please, try add next property, too
hibernate.jndi.java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
Best regards
James CaryMemberIt was the classpath. Adding the jnpserver.jar to the driver config got me going in the right direction. Still have some classpath issues, but I think I can get through those now. I’ll add the appropriate classes to my system classpath once I know what all I need.
Thank you for all your help
James
Haris PecoMemberJames,
I’m glad for your success.
Best regards
-
AuthorPosts