[hibernate-commits] Hibernate SVN: r10479 - in trunk/HibernateExt/tools: doc/reference/en/modules lib/testlibs src/java/org/hibernate/tool/ant src/test/org/hibernate/tool/ant src/testsupport
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Wed Sep 13 05:42:47 EDT 2006
Author: max.andersen at jboss.com
Date: 2006-09-13 05:42:33 -0400 (Wed, 13 Sep 2006)
New Revision: 10479
Modified:
trunk/HibernateExt/tools/doc/reference/en/modules/ant.xml
trunk/HibernateExt/tools/lib/testlibs/ejb3-persistence.jar
trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HibernateToolTask.java
trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/JPAConfigurationTask.java
trunk/HibernateExt/tools/src/test/org/hibernate/tool/ant/HibernateToolTest.java
trunk/HibernateExt/tools/src/testsupport/anttest-build.xml
Log:
HBX-750 add persistenceunit attribute on jpaconfiguration
+ test and docs
Modified: trunk/HibernateExt/tools/doc/reference/en/modules/ant.xml
===================================================================
--- trunk/HibernateExt/tools/doc/reference/en/modules/ant.xml 2006-09-12 06:55:07 UTC (rev 10478)
+++ trunk/HibernateExt/tools/doc/reference/en/modules/ant.xml 2006-09-13 09:42:33 UTC (rev 10479)
@@ -77,7 +77,7 @@
<property key="propertyName" value="value"/>
<propertyset ...>
(<configuration ...>|<annotationconfiguration ...>|
- <ejb3configuration ...>|<jdbcconfiguration ...>)
+ <jpaconfiguration ...>|<jdbcconfiguration ...>)
(<hbm2java>,<hbm2cfgxml>,<hbmtemplate>,...*)
</hibernatetool>]]></programlisting>
@@ -162,9 +162,9 @@
<para><literal>hibernatetool</literal> supports four different Hibernate
configurations: A standard Hibernate configuration
(<literal><configuration></literal>), Annotation based
- configuration (<literal><annotationconfiguration></literal>), EJB3
+ configuration (<literal><annotationconfiguration></literal>), JPA
persistence based configuration
- (<literal><ejb3configuration></literal>) and a JDBC based
+ (<literal><jpaconfiguration></literal>) and a JDBC based
configuration (<literal><jdbcconfiguration></literal>) for use
when reverse engineering.</para>
@@ -297,29 +297,31 @@
</section>
<section>
- <title>EJB3 based configuration (<ejb3configuration>)</title>
+ <title>JPA based configuration (<jpaconfiguration>)</title>
- <para>An <ejb3configuration> is used when you want to read the
- metamodel from EJB3/Hibernate Annotation where you want to use the
- auto-scan configuration as defined in the EJB3 spec. In other words,
- when you do not have a <literal>hibernate.cfg.xml</literal>, but
+ <para>An <jpaconfiguration> is used when you want to read the
+ metamodel from JPA/Hibernate Annotation where you want to use the
+ auto-scan configuration as defined in the JPA spec (part of EJB3).
+ In other words, when you do not have a <literal>hibernate.cfg.xml</literal>, but
instead have a setup where you use a
- <literal>persistence.xml</literal> packaged in an EJB3 compliant
+ <literal>persistence.xml</literal> packaged in an JPA compliant
manner.</para>
- <para>Note, in the current version there is no additional attribute
- support on <ejb3configuration> like found on
- <annotationconfiguration> and <configuration>. It will
+ <para><literal><jpaconfiguration></literal> will
simply just try and auto-configure it self based on the available
classpath, e.g. look for META-INF/persistence.xml.</para>
+
+ <para>The <literal>persistenceunit</literal> attribute can be used to select a specific
+ persistence unit. If no persistenceunit is specified it will automatically search for one and
+ if a unique one is found use it, but if multiple persistence units are available it will error.</para>
- <para>To use an <ejb3configuration> you will need to specify
+ <para>To use an <jpaconfiguration> you will need to specify
some additional jars from Hibernate EntityManager in the
<taskdef> of the hibernatetool. The following shows a full
setup:</para>
<programlisting><![CDATA[<path id="ejb3toolslib">
- <path refid="toolslib"/> <!-- ref to previously defined toolslib -->
+ <path refid="jpatoolslib"/> <!-- ref to previously defined toolslib -->
<path location="lib/hibernate-annotations.jar" />
<path location="lib/ejb3-persistence.jar" />
<path location="lib/hibernate-entitymanager.jar" />
@@ -329,20 +331,24 @@
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
- classpathref="ejb3toolslib" />
+ classpathref="jpatoolslib" />
<hibernatetool destdir="${build.dir}">
- <ejb3configuration />
+ <jpaconfiguration persistenceunit="caveatemptor"/>
<classpath>
<!-- it is in this classpath you put your classes dir,
- and/or ejb3 persistence compliant jar -->
- <path location="${build.dir}/ejb3/classes" />
+ and/or jpa persistence compliant jar -->
+ <path location="${build.dir}/jpa/classes" />
</classpath>
<!-- list exporters here -->
</hibernatetool>
]]></programlisting>
+
+<para>Note: <literal>ejb3configuration</literal> were the name used in previous versions. It still
+works but will emit a warning telling you to use <literal>jpaconfiguration</literal> instead.</para>
+
</section>
<section>
Modified: trunk/HibernateExt/tools/lib/testlibs/ejb3-persistence.jar
===================================================================
(Binary files differ)
Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HibernateToolTask.java
===================================================================
--- trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HibernateToolTask.java 2006-09-12 06:55:07 UTC (rev 10478)
+++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HibernateToolTask.java 2006-09-13 09:42:33 UTC (rev 10479)
@@ -61,6 +61,7 @@
}
public JPAConfigurationTask createEjb3Configuration() {
+ log( "<ejb3configuration> is deprecated. Use <jpaconfiguration> instead.", Project.MSG_WARN);
checkConfiguration();
configurationTask = new JPAConfigurationTask();
return (JPAConfigurationTask) configurationTask;
Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/JPAConfigurationTask.java
===================================================================
--- trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/JPAConfigurationTask.java 2006-09-12 06:55:07 UTC (rev 10478)
+++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/JPAConfigurationTask.java 2006-09-13 09:42:33 UTC (rev 10479)
@@ -11,6 +11,8 @@
import org.hibernate.util.ReflectHelper;
public class JPAConfigurationTask extends ConfigurationTask {
+
+ private String persistenceUnit = null;
public JPAConfigurationTask() {
setDescription("JPA Configuration");
@@ -23,7 +25,9 @@
Class clazz = ReflectHelper.classForName("org.hibernate.ejb.Ejb3Configuration", JPAConfigurationTask.class);
Object ejb3cfg = clazz.newInstance();
Method method = clazz.getMethod("configure", new Class[] { String.class, Map.class });
- method.invoke(ejb3cfg, new Object[] { null, overrides } );
+ if ( method.invoke(ejb3cfg, new Object[] { persistenceUnit, overrides } ) == null ) {
+ throw new BuildException("Persistence unit not found: '" + persistenceUnit + "'.");
+ }
method = clazz.getMethod("getHibernateConfiguration", new Class[0]);
return (Configuration) method.invoke(ejb3cfg, null);
@@ -31,6 +35,9 @@
catch(HibernateException he) {
throw new BuildException(he);
}
+ catch(BuildException be) {
+ throw be;
+ }
catch(Throwable t) {
throw new BuildException("Problems in creating a configuration for JPA. Have you remembered to add hibernate EntityManager jars to the classpath ?",t);
}
@@ -44,6 +51,14 @@
}
+ public String getPersistenceUnit() {
+ return persistenceUnit;
+ }
+
+ public void setPersistenceUnit(String persistenceUnit) {
+ this.persistenceUnit = persistenceUnit;
+ }
+
public void setConfigurationFile(File configurationFile) {
complain("configurationfile");
}
Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/ant/HibernateToolTest.java
===================================================================
--- trunk/HibernateExt/tools/src/test/org/hibernate/tool/ant/HibernateToolTest.java 2006-09-12 06:55:07 UTC (rev 10478)
+++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/ant/HibernateToolTest.java 2006-09-13 09:42:33 UTC (rev 10479)
@@ -70,8 +70,24 @@
assertTrue(ejb3.exists());
assertEquals(null, TestHelper.findFirstString("drop", ejb3));
+
+ assertTrue(getLog().indexOf("<ejb3configuration> is deprecated")>0);
+
}
+ public void testJPABogusPUnit() {
+ try {
+ executeTarget("jpa-bogusunit");
+ fail("Bogus unit accepted");
+ } catch(BuildException be) {
+ // should happen
+ }
+ }
+
+ public void testJPAPUnit() {
+ executeTarget("jpa-punit");
+ }
+
public void testHbm2JavaConfiguration() {
executeTarget("testanthbm2java");
}
Modified: trunk/HibernateExt/tools/src/testsupport/anttest-build.xml
===================================================================
--- trunk/HibernateExt/tools/src/testsupport/anttest-build.xml 2006-09-12 06:55:07 UTC (rev 10478)
+++ trunk/HibernateExt/tools/src/testsupport/anttest-build.xml 2006-09-13 09:42:33 UTC (rev 10479)
@@ -210,7 +210,7 @@
<copy file="ejb3test-hibernate.cfg.xml" tofile="${build.dir}/ejb3/classes/ejb3test-hibernate.cfg.xml" />
<hibernatetool destdir="${build.dir}">
- <jpaconfiguration/>
+ <ejb3configuration/>
<classpath>
<path location="${build.dir}/ejb3/classes" />
</classpath>
@@ -220,6 +220,95 @@
<antcall target="afterCfg2hbm" />
</target>
+ <target name="jpa-boguspunit">
+ <path id="annlib">
+ <path location="${build.dir}/../../lib/freemarker.jar" />
+
+ <path location="${build.dir}/../../lib/testlibs/hibernate3.jar" />
+ <path location="${build.dir}/../../lib/testlibs/hibernate-annotations.jar" />
+ <path location="${build.dir}/../../lib/testlibs/ejb3-persistence.jar" />
+ <path location="${build.dir}/../../lib/testlibs/hibernate-entitymanager.jar" />
+ <path location="${build.dir}/../../lib/testlibs/jboss-archive-browsing.jar" />
+ <path location="${build.dir}/../../lib/testlibs/javaassist.jar" />
+ <path location="${build.dir}/../classes" />
+ <path location="${hibernate-core.home}\jdbc\hsqldb.jar" />
+ <!-- <fileset dir="${hibernate-core.lib.dir}">
+
+ </fileset>-->
+ </path>
+ <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="annlib" />
+
+ <delete dir="${build.dir}/ejb3" />
+ <mkdir dir="${build.dir}/ejb3" />
+
+ <antcall target="prepareCfg2hbm" />
+ <hibernatetool>
+ <jdbcconfiguration propertyfile="../../etc/hibernate.properties" />
+ <hbm2java ejb3="true" jdk5="true" destdir="${build.dir}/ejb3/src" />
+ </hibernatetool>
+
+ <mkdir dir="${build.dir}/ejb3/classes" />
+ <javac classpathref="annlib" srcdir="${build.dir}/ejb3/src" destdir="${build.dir}/ejb3/classes" />
+
+ <copy file="ejb3test-persistence.xml" tofile="${build.dir}/ejb3/classes/META-INF/persistence.xml" />
+ <copy file="ejb3test-hibernate.cfg.xml" tofile="${build.dir}/ejb3/classes/ejb3test-hibernate.cfg.xml" />
+
+ <hibernatetool destdir="${build.dir}">
+ <jpaconfiguration persistenceunit="shouldnotbethere"/>
+ <classpath>
+ <path location="${build.dir}/ejb3/classes" />
+ </classpath>
+ <hbm2ddl export="false" outputfilename="ejb3.sql" />
+ </hibernatetool>
+
+ <antcall target="afterCfg2hbm" />
+ </target>
+
+ <target name="jpa-punit">
+ <path id="annlib">
+ <path location="${build.dir}/../../lib/freemarker.jar" />
+
+ <path location="${build.dir}/../../lib/testlibs/hibernate3.jar" />
+ <path location="${build.dir}/../../lib/testlibs/hibernate-annotations.jar" />
+ <path location="${build.dir}/../../lib/testlibs/ejb3-persistence.jar" />
+ <path location="${build.dir}/../../lib/testlibs/hibernate-entitymanager.jar" />
+ <path location="${build.dir}/../../lib/testlibs/jboss-archive-browsing.jar" />
+ <path location="${build.dir}/../../lib/testlibs/javaassist.jar" />
+ <path location="${build.dir}/../classes" />
+ <path location="${hibernate-core.home}\jdbc\hsqldb.jar" />
+ <!-- <fileset dir="${hibernate-core.lib.dir}">
+
+ </fileset>-->
+ </path>
+ <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="annlib" />
+
+ <delete dir="${build.dir}/ejb3" />
+ <mkdir dir="${build.dir}/ejb3" />
+
+ <antcall target="prepareCfg2hbm" />
+ <hibernatetool>
+ <jdbcconfiguration propertyfile="../../etc/hibernate.properties" />
+ <hbm2java ejb3="true" jdk5="true" destdir="${build.dir}/ejb3/src" />
+ </hibernatetool>
+
+ <mkdir dir="${build.dir}/ejb3/classes" />
+ <javac classpathref="annlib" srcdir="${build.dir}/ejb3/src" destdir="${build.dir}/ejb3/classes" />
+
+ <copy file="ejb3test-persistence.xml" tofile="${build.dir}/ejb3/classes/META-INF/persistence.xml" />
+ <copy file="ejb3test-hibernate.cfg.xml" tofile="${build.dir}/ejb3/classes/ejb3test-hibernate.cfg.xml" />
+
+ <hibernatetool destdir="${build.dir}">
+ <jpaconfiguration persistenceunit="ejb3test"/>
+ <classpath>
+ <path location="${build.dir}/ejb3/classes" />
+ </classpath>
+ <hbm2ddl export="false" outputfilename="ejb3.sql" />
+ </hibernatetool>
+
+ <antcall target="afterCfg2hbm" />
+ </target>
+
+
<target name="testantejb3hbm2java">
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="tasks.classpath" />
More information about the hibernate-commits
mailing list