How to configure jndi.properties for DataStore?

I'm struggling to connect a Java program to MySQL using JPA / Hibernate.

I am currently getting the following error when trying to call createEntityManagerFactory():

[main] ERROR org.hibernate.connection.DatasourceConnectionProvider - Could not find datasource: java:jdbc/myDataDS
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(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:75)

Googling seems to indicate that I need the jndi.properties file in META-INF in my class path, but I cannot find any information about what this file should contain in my case.

Edit: I am doing this offline, for now.

+1
source share
1 answer

File A jndi.propertiesshould be in the root path of the path and usually contains the JNDI server URL and the initial factory context. For example, with JBoss:

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=jnp://localhost:1099

Hibernate hibernate.cfg.xml. , WebLogic:

<property name="jndi.class">weblogic.jndi.WLInitialContextFactory</property>
<property name="jndi.url">t3://127.0.0.1:7001</property>
0

Source: https://habr.com/ru/post/1753717/


All Articles