Not logged in. · Lost password · Register

sergio
Member since Aug 2011
14 posts
Subject: 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

<persistence-unit name="testdb" transaction-type="JTA">
          
           <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>       
</persistence-unit>

3) Created a web.xml File for our webapp

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5"> 
  <persistence-context-ref>
      <persistence-unit-name>testdb</persistence-unit-name>
      <persistence-context-ref-name>persistence/em</persistence-context-ref-name>
  </persistence-context-ref> 
  <resource-ref>
      <res-ref-name>jdbc/postgresql</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
  </resource-ref>
</web-app>

4) Tried to create an EntityManagerFactory:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("testdb");

Does anyone have an idea, why it doesnt connect to the database?
pi256
Member since Jan 2007
103 posts
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.

4) Can you be more specific? How were you able to test this if your application doesn't even start?

Cheers
Hannes
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
Datenschutz | Kontakt
Powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2011 by Yves Goergen