History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: APF-712
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Matt Raible
Reporter: Matt Raible
Votes: 0
Watchers: 3
Operations

If you were logged in you would be able to see more operations.
AppFuse

Error "No name provided and several persistence units found" when using JPA

Created: 29/Mar/07 01:23 PM   Updated: 02/Oct/07 12:13 PM
Component/s: Persistence Layer
Affects Version/s: 2.0-M4
Fix Version/s: 2.0-M5


 Description  « Hide
I'm working on APF-565 (allowing dao.framework switching) and
experiencing an issue with the hibernate3 plugin.

Here's how I'm excluding Hibernate and including JPA in my sample project:

<dependency>
           <groupId>org.appfuse</groupId>
           <artifactId>appfuse-${web.framework}</artifactId>
           <version>${appfuse.version}</version>
           <type>warpath</type>
           <exclusions>
               <exclusion>
                   <groupId>org.appfuse</groupId>
                   <artifactId>appfuse-hibernate</artifactId>
               </exclusion>
           </exclusions>
       </dependency>
       <dependency>
           <groupId>org.appfuse</groupId>
           <artifactId>appfuse-${dao.framework}</artifactId>
           <version>${appfuse.version}</version>
       </dependency>

Here's the error I'm getting:

[INFO] ------------------------------------------------------------------------
[INFO] No name provided and several persistence units found
[INFO] ------------------------------------------------------------------------
[INFO] Trace
javax.persistence.PersistenceException: No name provided and several
persistence units found
       at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:226)
       at org.codehaus.mojo.hibernate3.configuration.JPAComponentConfiguration.createConfiguration(
JPAComponentConfiguration.java:26)
       at org.codehaus.mojo.hibernate3.configuration.AbstractComponentConfiguration.getConfiguratio
n(AbstractComponentConfiguration.java:32)
       at org.codehaus.mojo.hibernate3.exporter.Hbm2DDLExporterMojo.doExecute(Hbm2DDLExporterMojo.j
ava:87)
       at org.codehaus.mojo.hibernate3.HibernateExporterMojo.execute(HibernateExporterMojo.java:139

In pom.xml, I have:

<plugin>
               <groupId>org.codehaus.mojo</groupId>
               <artifactId>hibernate3-maven-plugin</artifactId>
               <version>2.0-alpha-1</version>
               <configuration>
                   <components>
                       <component>
                           <name>hbm2ddl</name>
                           <implementation>jpaconfiguration</implementation>
                       </component>
                   </components>
                   <componentProperties>
                       <drop>true</drop>
                       <jdk5>true</jdk5>

<propertyfile>target/classes/jdbc.properties</propertyfile>
                       <skip>${maven.test.skip}</skip>
                   </componentProperties>
               </configuration>
               <executions>
                   <execution>
                       <phase>process-test-resources</phase>
                       <goals>
                           <goal>hbm2ddl</goal>
                       </goals>
                   </execution>
               </executions>
               <dependencies>
                   <dependency>
                       <groupId>${jdbc.groupId}</groupId>
                       <artifactId>${jdbc.artifactId}</artifactId>
                       <version>${jdbc.version}</version>
                   </dependency>
               </dependencies>
           </plugin>

 All   Comments   Change History   FishEye      Sort Order:
Matt Raible - 29/Mar/07 01:23 PM
It appears this happens because the Hibernate3 Plugins scans JARs when using "jpaannotations". It finds a META-INF/persistence.xml in the warpath JARs and tries to use it. I'm going to exclude META-INF/persistence.xml from being included in "installed" AppFuse WARs so this problem doesn't happen for others.

Matt Raible - 29/Mar/07 02:24 PM
Solved by excluding META-INF/persistence.xml from any WARs. The Hibernate3 Plugin scans JARs and doesn't exclude these even though they're excluded in the WarPath plugin. META-INF is included in child WARs so tests will pass. However, they're excluded when creating a skinny WAR. If we find that this is not necessary, it should be easy enough to back out this change since the src/main/resources/META-INF directory in jsf, spring, struts and tapestry is linked to web/common/src/main/resources/META-INF using svn:externals.

Michael Horwitz - 01/Apr/07 03:07 PM
As persistence.xml is stored below META-INF, the exclude for the warpath plugin must be written as **/persistence.xml or META-INF/persistence.xml.

Barry Hobbs - 21/Sep/07 02:23 PM
With the full-source, and maven.test.skip set to false, I'm still seeing this issue with the APPFUSE-2.0 tag when using the JSF Modular archetype. Searching through the configuration files, I don't find a reference to excluding persistence.xml from anything, and I just see the addition of the test skip value in the core/pom.xml file. Am I missing something here? I can get it to work if I skip the tests, but I'd really like to be able to have the tests pass if you know what I mean ;)

Matt Raible - 21/Sep/07 02:29 PM
I believe this is caused by APF-910. If you're using JPA, you need to do two things:

rm -r core/src/test/resources/META-INF
rm web/src/main/resources/META-INF

Sami Kallio - 24/Sep/07 08:08 AM
I have the same issue even after the above rm commands. I am using Modular Spring MVC archetype and JPA. After mvn appfuse:full-source the issue occurs.

Matt Raible - 24/Sep/07 08:34 AM
Did you run "mvn clean" from the top level after running the following?

rm -r core/src/test/resources/META-INF
rm -r web/src/main/resources/META-INF

Sami Kallio - 28/Sep/07 01:17 PM
After that I am getting other exceptions. It looks to me like there is a problem with Java 1.6. I tried with another computer with Java 1.5 and it works. But even after doing everything from beginning mvn always produces something like below. Is there a problem with Modular Spring MVC+JPA+Java 1.6? (Hibernate with Java 1.6 is working)

WARN [main] DefaultNamespaceHandlerResolver.initHandlerMappings(133) | Ignoring namespace handler [org.springmodules.validation.bean.conf.namespace.ValidatorNamespaceHandler]: problem with handler class file or dependent class
java.lang.NoClassDefFoundError: Could not initialize class org.springmodules.validation.util.LibraryUtils
        at org.springmodules.validation.bean.conf.namespace.ValidatorNamespaceHandler.init(ValidatorNamespaceHandler.java:51)
        at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.initHandlerMappings(DefaultNamespaceHandlerResolver.java:123)
        at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.<init>(DefaultNamespaceHandlerResolver.java:96)
        at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.<init>(DefaultNamespaceHandlerResolver.java:82)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.createDefa


WARN [main] DefaultNamespaceHandlerResolver.initHandlerMappings(133) | Ignoring namespace handler [org.springmodules.validation.bean.conf.namespace.ValidatorNamespaceHandler]: problem with handler class file or dependent class
java.lang.NoSuchFieldError: IS_JAVA_1_6
        at org.springmodules.validation.util.LibraryUtils.<clinit>(LibraryUtils.java:40)
        at org.springmodules.validation.bean.conf.namespace.ValidatorNamespaceHandler.init(ValidatorNamespaceHandler.java:51)
        at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.initHandlerMappings(DefaultNamespaceHandlerResolver.java:123)
        at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.<init>(DefaultNamespaceHandlerResolver.java:96)
   

Matt Raible - 28/Sep/07 01:23 PM
It looks like Spring Modules is unable to handle Java 1.6.

Mark Helmstetter - 30/Sep/07 05:19 PM
FYI, I was getting this NoSuchFieldError: IS_JAVA_1_6 on another project. I found this:
http://www.nabble.com/bean-validator-issue-in-jdk-6-t3245736.html

which indicates that the solution/workaround is to use commons-lang 2.3. I added an explicit dependency or commons-lang version 2.3 in my pom.xml and voilla -- the problem goes away.

Sami Kallio - 02/Oct/07 12:13 PM
I already have this in my top level pom.xml:
 <commons.lang.version>2.3</commons.lang.version>

Is there something I can still do?