Wednesday, October 10, 2007

Seam-gen and TestNG problems

I created a project using Seam-gen, taking the database defaults (I wanted hsqldb for development anyway.)

First thing I wrote a test for the Manager/Action class that I was starting with. I also added a testng.xml to the src/test folder. I was using Eclipse so I right clicked on the build.xml's test target and ran it. Nothing.

The testng.xml file wasn't get copied to the test-build directory so I updated the build.xml withe the following :
  • test target - changed line 315 to read <xmlfileset dir="${test.dir}" includes="testng.xml" /> instead of <xmlfileset dir="${test.dir}" includes="*Test.xml" />
  • copytestclasses target - added <include name="*.xml" /> in the last copy statement so that the testng.xml file was copied from classes/test directory along with the class files
  • copytestclasses target - removed "if='eclipse.running'" from the target. I don't know why, but the files weren't copied at all with this qualifier even though I was running out of Eclipse.
The test ran from build.xml.

Right clicking and running the TestNG plugin didn't do anything though. I opened the Run dialog (Run -> Open Run Dialog) and updated the classpath of the TestNG test to include the lib/test folder and ran the test from there. I got a different but no better result. (The stack trace is pasted below in the possibly vain belief that someone may stumble onto this posting while Googling the same problem)

javax.persistence.PersistenceException: org.hibernate.HibernateException: The chosen transaction strategy requires access to the JTA TransactionManager
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:737)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)

I found this entry on JBoss' Forums which suggested using a non-jta-data-source in the persistence-test.xml. I updated my persistence-test.xml to the following (changes in bold) :

<?xml version="1.0" encoding="UTF-8"?>
<!-- Persistence deployment descriptor for tests -->
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">

<persistence-unit name="project_name" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>java:/DefaultDS</non-jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.show_sql" value="true"/>
<property name="jboss.entity.manager.factory.jndi.name" value="java:/project_nameEntityManagerFactory"/>
</properties>
</persistence-unit>

</persistence>

That did the trick; although, it doesn't appear that my test data is getting loaded. I'll blog that solution later.

Blogged with Flock

1 comment:

Lubomír Zrnečko said...

Hi,
I'm just wondering if you found out why nothing is saved into the database. I have experienced the same situation. (You wrote that you'll post on that later but I found nothing in newer posts :-()