-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: SOLVED: Persistence unit not found
PostPosted: Wed Jun 04, 2008 11:24 pm 
Newbie

Joined: Thu Oct 25, 2007 5:24 pm
Posts: 12
All i wanted was to generate ddl from JPA annotations. Little did i know it would be such a can of worms. First, I ran into the nasty Persistence unit not found. Had to find source code for Hibernate tools JPAConfigurationTask and Ejb3Configuration to see where they expected the persistence.xml to be.

The answer is: on the classpath and inside META-INF. Here's the structure for my web app, just to be able to run the tool:
/META-INF/classes/META-INF/persistence.xml

It works as long as your META-INF/persistance.xml is on the classpath.

Next thing failed in the ant build: javassist.jar missing. This is from JBOSS's project: https://sourceforge.net/project/showfil ... e_id=80766

Once all of that was set, i was finally able to run my hibernate tool to generate DDL from annotations.

ant script:

Code:
<taskdef
      name="hibernatetool"
      classname="org.hibernate.tool.ant.HibernateToolTask"
      classpathref="classpath.base" />   

<target name="jpa_ddl" depends="compile">
   <hibernatetool destdir="${config}">
       <classpath>
           <path location="${classes}"/>
       </classpath>
               
      <jpaconfiguration persistenceunit="p1" />

         <hbm2ddl
               export="false"
                   update="false"      
                   drop="true"
                create="true"
                   outputfilename="db_schema.sql"
                 delimiter=";"
                 format="true"
                   haltonerror="true"
            />      
   </hibernatetool>
</target>


persistence.xml in {classpath}/META-INF/
Code:
<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="p1" transaction-type="RESOURCE_LOCAL">
      <class>net.xyzpackage.jpa.Property</class>   
      <properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
      </properties>   
   </persistence-unit>
</persistence>


[/code]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.