Vaadin and JPA

Hello All

I’m an old Delphi (Yes I know!) developer - and I finally got around to reading the ‘Book of Vaadin’ thru completely…
This documentation is superb - a model of clarity - and I’ve really enjoyed myself!

I am struggling with binding data to a Vaadin Form or Table component to a MySQL Database - and the prospect of using Hibernate makes my heart sink…

I do not find the Hibernate example at all clear - that’s down to me…

Now this is all down to my own limitations, that’s for sure - can anyone help with using JPA/Dali tooling on a Vaadin Project. I’ve tried adding JPA as a facet to a Vaadin Project- but it just does not work for me.

Sure - using the MySQL Sakila Database I can create an entity class from a table - I’ve used the simple Actors Table from Sakila.


I cannot update the persistence.xml file - I have no idea why…
Form Component shows the fields - but they are empty…

Now all this stuff would be trivial in Delphi - but now I’m really struggling…

Any guidance will be appreciated - meanwhile I’ll keep trying!

Kindest Regards

Jim Fergusson

Hello All

I hope this does not come across as to much of a moan - but I’ve had a frustrating day…

None of the following is a criticism of Vaadin.
I also know all of the tools I am using are Open Source - so I have to work at it - but surely connecting a web server to a database with a Java Application should be standard stuff…why is it so much of a pain?

I can run a standard Vaadin ‘no binding’ application on Tomcat - looks great…

Now for data binding.

JPA does not appear to work with Apache Tomcat - could not find anything in Tomcat help - but found info on the web that it can be done, but not without following many confusing - to me - pages of configuration. so I looked up Apache OpenJPA - Ah! - So Apache Geronimo supports OpenJPA natively!

Install Geronimo - but the Eclipse Geronimo Plug-in does not work - reported in July’09 - but still broken… so ‘workaround’ is to install from a nightly ‘unstable’ build - so OK at least it installs and I can create a Server Instance in Eclipse.

I can run a standard ‘no binding’ app on Geronimo - but as soon as Persistence is added it fails

16 hours so far - and I can’t display a single row from the Author’s table (MySQL Sakila Database)

I almost despair…

My son uses Code Ignitor and PHP - and can do this stuff in minutes…


Jim Fergusson

What kind of error messages are you getting? Does JPA create the database schema for you (in other words, does it even connect to the database)?

Where do you have you persistence.xml file? It needs to be in the META-INF folder, but I’ve noticed that putting the xml file in the WebContent/META-INF/ folder doesn’t help, as it needs to be in the classpath (and adding it in the project properties didn’t help either). What I had to do was to create a separete “META-INF” -folder
under the src-folder
, that’s right, in the same place with your code. When I put the peristence.xml file in that folder, everything started to work for me.

Hello Kim

You have no idea how much I appreciate your help…

Yes - JPA creates the schema OK

persistence.xml appears to be in the right place at: src/META_INF/persistence.xml - but I need to check the contents!

Really great of you to help

Kindest Regards from an old Scot!



I really appreciate the help so far…
At the risk of boring everyone, when it’s almost certainly my fault…

Contents of my persistence.xml file are:

<?xml version="1.0" encoding="UTF-8"?> org.apache.openjpa.persistence.PersistenceProviderImpl com.example.vaading4.Actor

Anything odd here?

Error message returned from Geronimo / Jetty

There were errors initializing your configuration: <openjpa-1.2.1-r752877:753278 fatal user error> org.apache.openjpa.util.UserException: A connection could not be obtained for driver class “com.mysql.jdbc.Driver” and URL “jdbc:mysql://localhost:3308/sakila”. You may have specified an invalid URL.
at org.apache.openjpa.jdbc.schema.DataSourceFactory.newConnectException(
at org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(
at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.createConnectionFactory(
at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getConnectionFactory(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at org.apache.openjpa.lib.conf.ConfigurationImpl.instantiateAll(
at org.apache.openjpa.conf.OpenJPAConfigurationImpl.instantiateAll(
at org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(
at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(
at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(
at com.example.vaading4.Vaading4Application.init(
at com.vaadin.Application.start(
at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.startApplication(
at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(
at javax.servlet.http.HttpServlet.service(
at org.mortbay.jetty.servlet.ServletHolder.handle(
at org.apache.geronimo.jetty6.InternalJettyServletHolder.handle(
at org.mortbay.jetty.servlet.ServletHandler.handle(
at org.mortbay.jetty.servlet.SessionHandler.handle(
at org.mortbay.jetty.handler.ContextHandler.handle(
at org.mortbay.jetty.webapp.WebAppContext.handle(
at org.apache.geronimo.jetty6.handler.TwistyWebAppContext.access$101(
at org.apache.geronimo.jetty6.handler.TwistyWebAppContext$TwistyHandler.handle(
at org.apache.geronimo.jetty6.handler.ThreadClassloaderHandler.handle(
at org.apache.geronimo.jetty6.handler.InstanceContextHandler.handle(
at org.apache.geronimo.jetty6.handler.UserTransactionHandler.handle(
at org.apache.geronimo.jetty6.handler.ComponentContextHandler.handle(
at org.apache.geronimo.jetty6.handler.TwistyWebAppContext.handle(
at org.mortbay.jetty.handler.ContextHandlerCollection.handle(
at org.mortbay.jetty.handler.HandlerCollection.handle(
at org.mortbay.jetty.handler.HandlerWrapper.handle(
at org.mortbay.jetty.Server.handle(
at org.mortbay.jetty.HttpConnection.handleRequest(
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(
at org.mortbay.jetty.HttpParser.parseNext(
at org.mortbay.jetty.HttpParser.parseAvailable(
at org.mortbay.jetty.HttpConnection.handle(
at org.apache.geronimo.pool.ThreadPool$
at org.apache.geronimo.pool.ThreadPool$
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(
at java.util.concurrent.ThreadPoolExecutor$
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in classloader org.apache.geronimo.configs/openjpa/2.1.4/car
at org.apache.geronimo.kernel.config.MultiParentClassLoader.loadOptimizedClass(
at org.apache.geronimo.kernel.config.MultiParentClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
at java.lang.ClassLoader.loadClassInternal(
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(
at org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(
… 48 more

The url for mysql is correct - see anything else wrong??

Any help will be much appreciated


Jim Fergusson

Seems like you don’t have the mysql driver jar in your classpath. For example, I have mysql-connector-java-5.1.7-bin.jar in WebContent/WEB-INF/lib/. You can download the driver at

Hello Kim

I’m really
(Scottish expression indicting happiness!)

I was well aware that this newbie problem had nothing to do with Vaadin…so you deserve thanks for even looking at it.

Works like a dream now!

Thanks so much for the care you took to solve it - I had the MySQL jar just about everywhere else but the classpath!
The beer is on me if we ever meet!

Vaadin really is superb -
the framework and you developers

Kindest Regards


No problem. Happy I was able to be of assistance :slight_smile: