-->
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.  [ 11 posts ] 
Author Message
 Post subject: [schemaexport] Ant Tool - Wildcard Classes?
PostPosted: Mon Jan 09, 2006 6:28 pm 
Regular
Regular

Joined: Sun Sep 26, 2004 9:27 pm
Posts: 75
Location: Atlanta, GA, USA
I am generating the DDL from a series of classes containing JSR 220 annotations. I have successfully written the build.xml and hibernate.cfg.xml for this task. However, keeping up with each class to map within the cfg.xml file is tedious, especially with several different developers.

Is there any way to direct the schemaexport tool to generate the DDL for all classes, or for a set using wildcards?

I've attempted this using different attributes from the Hibernate 3.0 DTD "mapping" element to no avail. I also have tried dynamically generating a cfg.xml file, but have a chicken-and-egg problem (no DDL to generate from).

Any hints or insight appreciated. For completeness (and help for anyone else needing them), my cfg.xml and build.xml are given below.

hibernate.cfg.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
      "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory name="context">
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.connection.url">jdbc:mysql://SERVERNAME/mydatabase</property>
        <property name="hibernate.connection.username">myusername</property>
        <property name="hibernate.connection.password">mypassword</property>
         <mapping class="p2p.common.security.Group"/>
         <mapping class="p2p.common.security.Permission"/>
    </session-factory>
</hibernate-configuration>


build.xml task
Code:
   <target name="hibernate-mappings" description="Generates Hibernate class descriptor files." depends="properties">

      <path id="path.hibernatetools">
         <fileset dir="${dir.lib.hibernate.tools.plugin}\lib\tools" includes="hibernate-tools.jar" />
         <fileset dir="${dir.lib.hibernate.tools.plugin}\lib\hibernate" includes="hibernate3.jar" />
         <fileset dir="${dir.lib.hibernate.tools.plugin}\lib\hibernate" includes="commons-logging*.jar" />
         <fileset dir="${dir.lib.hibernate.tools.plugin}\lib\annotations" includes="hibernate-annotations.jar" />
         <fileset dir="${dir.lib.hibernate.tools.plugin}\lib\hibernate" includes="dom4j*.jar" />
         <fileset dir="${dir.lib.hibernate.tools.plugin}\lib\annotations" includes="ejb3-persistence.jar" />
         <fileset dir="${dir.lib.hibernate.tools.plugin}\lib\hibernate" includes="commons-collections*.jar" />

         <!-- Include all database driver, cglib, and ehcache JARs -->
         <fileset dir="${dir.lib.database.runtime}" includes="*.jar" />
         <!-- Lastly, the Java JTA jar is required. -->
         <fileset dir="${dir.lib.common}" includes="jta*.jar" />
         
      </path>


      <!-- Defines the hibernatedoclet task to be executed below. -->
      <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="path.hibernatetools" />

      <hibernatetool destdir="${dir.source.sql}">
         <classpath>
            <path location="${dir.build}" />
         </classpath>
         
         <annotationconfiguration configurationfile="${basedir}/conf/local/hibernate.cfg.xml"  /> 

         <hbm2ddl outputfilename="hibernate.ddl.sql" drop="false" export="false" />
      </hibernatetool>
   </target>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 10, 2006 3:13 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
nope, not yet possible. Needs an ejb3configuration to do the autoscanning.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 10, 2006 10:45 am 
Regular
Regular

Joined: Sun Sep 26, 2004 9:27 pm
Posts: 75
Location: Atlanta, GA, USA
Thanks for the reply, Max.


Top
 Profile  
 
 Post subject: Revisit.
PostPosted: Tue May 30, 2006 10:16 pm 
Regular
Regular

Joined: Sun Sep 26, 2004 9:27 pm
Posts: 75
Location: Atlanta, GA, USA
I'd like to revisit this topic using Hibernate, Annotations, and Entity Manager 3.2 CR1, with Tools 3.1 beta 5.

I'm attempting to use the ejbconfiguration as specfied earlier. Here is my ANT script snippet, as following the current documentation.

Code:
      <hibernatetool destdir="${dir.source.sql}">
         <ejb3configuration />
         <classpath>
            <path location="${dir.build}" />
         </classpath>
         <!--
         <annotationconfiguration configurationfile="${basedir}/conf/local/hibernate.cfg.xml"  /> 
         -->
         <hbm2ddl outputfilename="hibernate.ddl.sql" drop="false" export="false" />
      </hibernatetool>



However, since ejbconfiguration doesn't utilize a configurationfile attribute, it doesn't know what dialect to use.

Code:
[hibernatetool] org.hibernate.HibernateException: The dialect was not set. Set the property hibernate.dialect.


I attempted to add the hibernate.dialect property to a generic persistence.xml file, but it apparently wasn't found.

How do I specify these parameters for the ejbconfiguration since I can't specify a properties or XML config file?


Top
 Profile  
 
 Post subject: Re: Revisit.
PostPosted: Tue May 30, 2006 10:21 pm 
Regular
Regular

Joined: Sun Sep 26, 2004 9:27 pm
Posts: 75
Location: Atlanta, GA, USA
lukasbradley wrote:
I attempted to add the hibernate.dialect property to a generic persistence.xml file, but it apparently wasn't found.

How do I specify these parameters for the ejbconfiguration since I can't specify a properties or XML config file?


I didn't have my persistence.xml file within a META-INF subdirectory. It found the dialect, but now I have more issues.

I'll post a solution if I find one.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 30, 2006 10:32 pm 
Regular
Regular

Joined: Sun Sep 26, 2004 9:27 pm
Posts: 75
Location: Atlanta, GA, USA
Think I'm stuck for a bit. It's trying to find a datasource, but I don't know how to define it correctly.

My persistence.xml file:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<entity-manager>
   <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.username" value="root"/>
       <property name="hibernate.connection.password" value="password"/>
       <property name="hibernate.connection.url" value="jdbc:mysql://MEDIA02/games"/>
       <property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider"/>
   </properties>
</entity-manager>


The error:

Code:
[hibernatetool] javax.persistence.PersistenceException: org.hibernate.HibernateException: Could not find datasource
[hibernatetool] org.hibernate.HibernateException: Could not find datasource
[hibernatetool] javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 31, 2006 4:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
set it up to use a jdbc connection manager instead of a datasource.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 31, 2006 10:51 am 
Regular
Regular

Joined: Sun Sep 26, 2004 9:27 pm
Posts: 75
Location: Atlanta, GA, USA
max wrote:
set it up to use a jdbc connection manager instead of a datasource.


In the persistence.xml?


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 31, 2006 11:02 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes - there is no datasources available in eclipse nor ant by default AFAIK :)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 31, 2006 11:40 am 
Regular
Regular

Joined: Sun Sep 26, 2004 9:27 pm
Posts: 75
Location: Atlanta, GA, USA
max wrote:
yes - there is no datasources available in eclipse nor ant by default AFAIK :)


I thought you could have meant a <jdbcconfiguration/> or something along those lines.

Can you point me in the direction of how to do this within the persistence.xml file? I'm looking all over, but its not explicitly stated anywhere in the new 3.0 spec, in the JBOSS documentation, or on any Google searches.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 31, 2006 1:48 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
from entity manager docs:

"jta-data-source, non-jta-data-source

This is the JNDI name of where the javax.sql.DataSource is located. When running without a JNDI available Datasource, you must specify JDBC connections with Hibernate specific properties (see below)."

..from below:

"Here is a typical configuration in a J2SE environment
<persistence>
<persistence-unit name="manager1" transaction-type="RESOURCE_LOCAL">
<class>org.hibernate.ejb.test.Cat</class>
<class>org.hibernate.ejb.test.Distributor</class>
<class>org.hibernate.ejb.test.Item</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/>
<property name="hibernate.connection.username" value="sa"/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.connection.url" value="jdbc:hsqldb:."/>
<property name="hibernate.max_fetch_depth" value="3"/>

<!-- cache configuration -->
<property name="hibernate.ejb.classcache.org.hibernate.ejb.test.Item" value="read-write"/>
<property name="hibernate.ejb.collectioncache.org.hibernate.ejb.test.Item.distributors" value="read-write, RegionName"/>

<!-- alternatively to <class> and <property> declarations, you can use a regular hibernate.cfg.xml file -->
<!-- property name="hibernate.ejb.cfgfile" value="/org/hibernate/ejb/test/hibernate.cfg.xml"/ -->
</properties>
<persistence-unit>
</persistence>"

_________________
Max
Don't forget to rate


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

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.