Database connection via JPA and JNDI

Disclaimer: Dieser Thread wurde aus dem alten Forum importiert. Daher werden eventuell nicht alle Formatierungen richtig angezeigt. Der ursprüngliche Thread beginnt im zweiten Post dieses Threads.

Database connection via JPA and JNDI
I have a problem to connect to my localdatabase via JNDI and tha Java JPA Persistence Unit usind EclipseLink.
The database with JPA only works fine. But when i try to connect via JNDI, there is no connection and our webapp says
‘HTTP Status 500 - com.vaadin.server.ServiceException: java.lang.NoClassDefFoundError: Could not initialize class com.fau.amos.team2.WoundManagement.WoundManagementUI’

I did the following:

  1. Changed my tomcat7 context.xml as described in lecture:
    Used the credentials of my local running postgresql server.

  2. Configured the persistance.xml of our webapp

	<jta-data-source>java:comp/env/jdbc/postgresql</jta-data-source>
	
	<class>com.fau.amos.team2.WoundManagement "..."</class> <!-- classes used for OR-Mapper -->
	
	        <exclude-unlisted-classes>false</exclude-unlisted-classes>
	<shared-cache-mode>NONE</shared-cache-mode>
	
	<properties>
 		<property name="eclipselink.logging.level" value="FINE"/>
 		<property name="eclipselink.ddl-generation" value="create-or-extend-tables"/>
 		<property name="eclipselink.ddl-generation.output-mode" value="database"/>
	</properties>		
  1. Created a web.xml File for our webapp



testdb
persistence/em


jdbc/postgresql
javax.sql.DataSource
Container

  1. Tried to create an EntityManagerFactory:
    EntityManagerFactory emf = Persistence.createEntityManagerFactory(“testdb”);

Does anyone have an idea, why it doesnt connect to the database?


Hi,

I have a feeling that JNDI is not directly responsible for your exception.

Are you sure your web.xml file is correct? Not in respect to JNDI but in respect to Vaadin. I think you are missing some important entries:
https://vaadin.com/book/-/page/application.environment.html

Usually, if your JNDI configuration doesn’t work you’ll get an exception as soon as you do the first access to the DataSource, but that wouldn’t be a NoClassDefFoundError. Maybe a NamingException.

  1. Can you be more specific? How were you able to test this if your application doesn’t even start?

Cheers
Hannes