Getting started w/persistence

I’m experimenting with Vaadin - trying to get access to a database. Unfortunately, I’ve spent 15 years using Netbeans, and now I have to do this with Eclipse, so I’m in way over my head at the moment… Any pointers here would be appreciated.

I’ve loaded Eclipse and the Vaadin jar file along with eclipselink and its associated jar files and the appFoundation plugin jar file. I started with the Vaadin hello world program and added one line - just to see if I could connect to a database - so my code looks like this:

package com.example.vtest;

import org.vaadin.appfoundation.persistence.facade.FacadeFactory;

import com.vaadin.Application;
import com.vaadin.ui.*;
import com.verisign.common.utils.VRSNLogger;

public class VtestApplication extends Application {
/**
*
*/
private static final long serialVersionUID = 1L;

private static final VRSNLogger Logger = VRSNLogger.getLogger(VtestApplication.class);
@Override
public void init() {
	Window mainWindow = new Window("Vtest Application");
	Logger.debug("11111");    // The log statement shows up correctly in Tomcat log file...
	Label label = new Label("Hello Vaadin user");
	mainWindow.addComponent(label);
	setMainWindow(mainWindow);
	Logger.debug("22222");
	try {
		FacadeFactory.registerFacade("PUVtest", true);     // *** THIS FAILS
	} catch (InstantiationException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (IllegalAccessException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}

}

My persistence.xml file looks like this:

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




org.eclipse.persistence.jpa.PersistenceProvider

com.example.TestPojo
false











When I put the .war file into my Tomcat container and connect to it, the 2 log statements show up in the tomcat log file and then it throws an exception:

javax.servlet.ServletException: javax.persistence.PersistenceException: No Persistence provider for EntityManager named PUVtest

My library directory looks like:

$ pwd
/VTest/WebContent/WEB-INF/lib

$ ls
appfoundation.jar
eclipselink.jar
eclipselink-jpa-modelgen_2.2.0.v20110202-r8913.jar
javax.persistence_1.0.0.jar
javax.persistence_2.0.3.v201010191057.jar
log4j-1.2.14.jar
mysql-connector-java-5.1.10-bin.jar
vaadin-6.5.2.jar
VRSN_Common.jar

So can someone tell me what jar file I need to supply to fix this? And where do I find it? I was under the impression that the javax_persistence… files should handle this. Do I have them in the wrong directory?

Thanks,

nbc

Hi,

have you put the persistence.xml file in a correct place where it can be found?

Quote from
AppFoundation wiki
:

Yes - I found that one - I had originally put it in the WebContent folder, but I moved it - the error with the file in the wrong place was a different one - now it looks like it actually gets to run the program and then fails looking for the Persistence Unit object…

nbc

I may have found my answer - not certain just yet. I have been unable to locate the Provider class within Eclipse, but I downloaded and installed the OpenJPA package from apache. I then changed the provider line in the persistence.xml file to look like:

org.apache.openjpa.persistence.PersistenceProviderImpl

And now the call

FacadeFactory.registerFacade(“PUVtest”, true);

does not throw an exception. I still have to define a java class corresponding to one of my database tables and see if I can actually read the data, but it looks like I’ve gotten by the first hurdle…

nbc

Ok - now I’m seriously confused. It looked like it was working. So I added a java class, (Sgname - extended AbstractPojo), and put that class in the persistence.xml file. And now it fails again, trying to get the provider.

It is quite possible that I don’t understand exactly what is needed to access the database here. I’ve used Netbeans with Hibernate successfully in the past, but this is my first attempt with OpenJPA, Vaadin etc…

The persistence file looks like:

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




org.apache.openjpa.persistence.PersistenceProviderImpl

com.example.vtest.Sgname
false











And the relevant code is:

            try {
		FacadeFactory.registerFacade("PUVtest", true);       // **** BLOWS UP HERE...
		Logger.debug("33333");
		vSgname = (Vector<Sgname>) FacadeFactory.getFacade().list(Sgname.class);
		Logger.info("There are " + vSgname.size() + " Support Group Names");
	} catch (InstantiationException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (IllegalAccessException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

Error output:

Mar 10, 2011 10:27:33 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet Vtest Application threw exception
javax.persistence.PersistenceException: No persistence providers available for “PUVtest” after trying the following discovered implementations: org.eclipse.persistence.jpa.PersistenceProvider, org.apache.openjpa.persistence.PersistenceProviderImpl
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:182)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:72)
etc. etc.

Can someone tell me what I’m doing wrong here??? persistence.xml is located in the src directory -

$ pwd
<path_to_WorkSpace/VTest

$ find ./src
./src
./src/log4j.properties
./src/persistence.xml
./src/com
./src/com/example
./src/com/example/vtest
./src/com/example/vtest/VtestApplication.java
./src/com/example/vtest/Sgname.java

and my libraries are listed here:

ncohen@nbc-verisign: find ./WebContent/
./WebContent/
./WebContent/META-INF
./WebContent/META-INF/MANIFEST.MF
./WebContent/META-INF/persistence.xml
./WebContent/WEB-INF
./WebContent/WEB-INF/web.xml
./WebContent/WEB-INF/lib
./WebContent/WEB-INF/lib/appfoundation.jar
./WebContent/WEB-INF/lib/mysql-connector-java-5.1.10-bin.jar
./WebContent/WEB-INF/lib/VRSN_Common.jar
./WebContent/WEB-INF/lib/derby-10.5.3.0_1.jar
./WebContent/WEB-INF/lib/geronimo-jms_1.1_spec-1.1.1.jar
./WebContent/WEB-INF/lib/serp-1.13.1.jar
./WebContent/WEB-INF/lib/javax.persistence_2.0.3.v201010191057.jar
./WebContent/WEB-INF/lib/eclipselink-jpa-modelgen_2.2.0.v20110202-r8913.jar
./WebContent/WEB-INF/lib/commons-logging-1.0.4.jar
./WebContent/WEB-INF/lib/geronimo-jpa_2.0_spec-1.1.jar
./WebContent/WEB-INF/lib/vaadin-6.5.2.jar
./WebContent/WEB-INF/lib/commons-collections-3.2.1.jar
./WebContent/WEB-INF/lib/openjpa-2.1.0.jar
./WebContent/WEB-INF/lib/geronimo-validation_1.0_spec-1.1.jar
./WebContent/WEB-INF/lib/geronimo-jta_1.1_spec-1.1.1.jar
./WebContent/WEB-INF/lib/commons-pool-1.5.4.jar
./WebContent/WEB-INF/lib/commons-beanutils-1.8.3.jar
./WebContent/WEB-INF/lib/commons-lang-2.4.jar
./WebContent/WEB-INF/lib/javax.persistence_1.0.0.jar
./WebContent/WEB-INF/lib/commons-dbcp-1.4.jar
./WebContent/WEB-INF/lib/org.apache.bval.bundle-0.2-incubating.jar
./WebContent/WEB-INF/lib/eclipselink.jar
./WebContent/WEB-INF/lib/log4j-1.2.14.jar

Thanks very much,

nbc

And just as I submitted that last message, I realized that I had put the persistence.xml file in the src directory, but not in src/META-INF - and that seems to make a difference. My program is still crashing, but it looks like it found the provider. Not sure why it appeared to work earlier…

Sorry for the long posts here - newbie struggling…

nbc

How does it crash? Is the problem the one you described
in this thread
or is it something else? And what comes to the persistence provider, AppFoundation is designed to be used together with EclipseLink, so I don’t know if everything will work properly with OpenJPA. You can download the newest version of EclipseLink from
this download page
. Download the installer package and follow the instructions in AppFoundation’s
quick install guide
(step 3).

I am not familiar with EclipseLink - I’ll take a look at that - thanks. It wasn’t clear to me exactly what I needed to set as the JPA provider here…

I have temporarily set the appFoundation aside - I’ve been experimenting with just using the SQLContainer, and I did manage to get that to connect to my database and load in at least one table. I think (but I’m not sure) that the SQLContainer requires more work on my part than the appFoundation would - but I’ll keep experimenting for a bit

Thanks for the info.

nbc