LiftConsole and JPA

14 views
Skip to first unread message

Janico Greifenberg

unread,
Dec 8, 2009, 3:16:46 PM12/8/09
to lif...@googlegroups.com
Hi,
I've started to experiment with a Lift project that uses JPA for
persistence. While it works just fine in the web application run with
mvn jetty:run, I cannot use the model classes from the LiftConsole
(mvn scala:console -DmainConsole=LiftConsole). When I try for example

Model.find(classOf[Article], 1)

I get the following error:

java.lang.ClassNotFoundException: javax.transaction.SystemException
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:315)
at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
at java.lang.Clas...

Model is the EntityManager that I created accorting to chapter 10 from
the Lift book. Article is an entity class and 1 is an id that exists
in the database.

I'm using lift version 1.1-M7 and the following persistence.xml

<persistence>
<persistence-unit name="jpa-dossier" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="hibernate.dialect"
value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.connection.driver_class"
value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.url"
value="jdbc:mysql://localhost/dossier"/>
<property name="hibernate.max_fetch_depth" value="3"/>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="update" /><property
name="hibernate.connection.username" value="***">
</property>
<property name="hibernate.connection.password" value="***"></property>
</properties>
</persistence-unit>
</persistence>

Is there something that I need to initialize to get this to work?

So long
Janico

Derek Chen-Becker

unread,
Dec 8, 2009, 3:59:33 PM12/8/09
to lif...@googlegroups.com
It looks like the JTA jar isn't being added to the classpath for the LiftConsole runner. I've never touched scala:console, so I'm not sure what you would need to do to make it work. Off the top of my head, you might need to put the dependencies for JPA into the plugin config, but I'm not positive.

Derek


--

You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.



Janico Greifenberg

unread,
Dec 9, 2009, 4:35:32 AM12/9/09
to lif...@googlegroups.com
I had excluded JTA in the pom.xml, because I copied the dependencies
from the JPADemo example. After I removed that exclusion, the console
works, so the practical problem is solved.
I'm still a bit confused, however, why I need JTA when I use
RESOURCE_LOCAL as transaction-type. And why does it work under jetty,
but not in the console?

So long
Janico
--
http://jgre.org

Derek Chen-Becker

unread,
Dec 9, 2009, 10:05:18 AM12/9/09
to lif...@googlegroups.com
I'm not sure why the console would need JTA, especially if you've set things to RESOURCE_LOCAL. If you could send a full stack trace of the exception that might help pinpoint it.

Derek

Janico Greifenberg

unread,
Dec 9, 2009, 12:21:44 PM12/9/09
to lif...@googlegroups.com
The stack trace is attached.

So long
Janico
jta-exception.out

Derek Chen-Becker

unread,
Dec 9, 2009, 5:20:53 PM12/9/09
to lif...@googlegroups.com
The exception is being thrown by Hibernate:

java.lang.NoClassDefFoundError: javax/transaction/SystemException
        at org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:39)
        at org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:34)


For whatever reason, Hibernate wants to load JTA even though your persistence unit is marked RESOURCE_LOCAL. This seems like a bug in Hibernate. All that ScalaJPA does is try to create the EM, but the creation should be controlled entirely by the persistence.xml metadata.

Derek
Reply all
Reply to author
Forward
0 new messages