The Artima Developer Community
Sponsored Link

Java Answers Forum
GeneratingClasses and mappingFiles from database schema/ sql with ant/maven

2 replies on 1 page. Most recent reply: Nov 25, 2005 4:03 AM by assan rekowski

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
assan rekowski

Posts: 22
Nickname: haiaw
Registered: Sep, 2003

GeneratingClasses and mappingFiles from database schema/ sql with ant/maven Posted: Nov 20, 2005 4:43 AM
Reply to this message Reply
Advertisement
hi,
I have an application using the the following ant script (it creates mapping files - hbms and sql schema for my database, basing on xdoclet for hibernate), (application also use spring beans in configuration file):

<?xml version="1.0" encoding="UTF-8"?>
<project name="demo" default="generate">

<property file="build.properties" />

<target name="init">

<echo message="Clening..."/>
<delete dir="target" failonerror="false"/>

<echo message="Creating folders..."/>
<mkdir dir="target"/>
<mkdir dir="target/classes"/>
<mkdir dir="target/jar"/>

<echo message="Defining xdoclet2 ant task..."/>
<path id="xdoclet2.task.classpath">
<fileset dir="lib/xdoclet">
<include name="*.jar"/>
</fileset>
</path>

<path id="project.classpath">
<fileset dir="lib">
<include name="*.jar"/>
</fileset>
</path>

<taskdef
name="xdoclet2"
classname="org.xdoclet.ant.XDocletTask"
classpathref="xdoclet2.task.classpath"
/>
</target>
<target name="generate" depends="init" description="Cleans and builds everything.">
<echo message="Generating hbms..."/>
<xdoclet2>
<fileset dir="source/src">
<include name="**/*Model.java"/>
</fileset>

<component
classname="org.xdoclet.plugin.hibernate.HibernateMappingPlugin"
destdir="target/hbm"
version="2.0"
/>
</xdoclet2>

<echo message="Compiling..."/>
<javac classpathref="project.classpath" destdir="target/classes"
srcdir="source/src">
</javac>

<echo message="Creating jar..."/>
<jar destfile="target/jar/demo.jar">
<fileset dir="target/classes"/>
<fileset dir="resources"/>
<fileset dir="target/hbm"/>
</jar>

<path id="hibernate.task.classpath">
<fileset dir="lib">
<include name="*.jar"/>
</fileset>
<fileset dir="target/jar">
<include name="*.jar"/>
</fileset>
</path>

<echo message="Creating database schema..."/>
<taskdef name="schemaexport"
classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask"
classpathref="hibernate.task.classpath"/>

<schemaexport
properties="resources/hibernate.properties"
quiet="no"
text="no"
drop="no"
delimiter=";"
output="target/schema-export.sql">
<fileset dir="target/hbm">
<include name="**/*.hbm.xml"/>
</fileset>
</schemaexport>

</target>

</project>




EXAMPLE MAPPING FILE:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate -mapping>
<class table="DEMO_ADDRESS" name="amg.demo.model.AddressModel">
<id unsaved-value="null" name="id">
<generator class="native">
<param name="sequence">id_seq</param>
</generator>
</id>
<version unsaved-value="undefined" name="version" column="version" type="java.lang.Long"/>
<property name="firstName"/>
<property name="lastName"/>
<property name="type" type="amg.demo.model.AddressTypeEnum"/>
<property name="zipCode"/>
</class>
</hibernate-mapping>


I wish I would know how to make an inverse operation - I mean having the sql database schema I should generate classes and propably the mapping xml-es.

Could u please give me some example applications/ant or maven scripts with some database sql schemat or some not very complicated links to the tutorials concerning this problem?


Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: GeneratingClasses and mappingFiles from database schema/ sql with ant/m Posted: Nov 20, 2005 10:32 PM
Reply to this message Reply
Google hibernate Tutorial.

There is a great tutorial (3rd Chapter or so) on
the site www.hibernate.org Should get you started
with Configuring Hibernate - this includes setting
up the cfg file to point to the appropriate Driver
(I'm using jdbc-postgres to connect to postgres for
instance), pool connections, admin stuff: passwords,
login, etc; the actual Hibernate Mappings, the beans
that use these Mappings, etc.

On the hibernate site you want to look for the link
documentation and then manual or something to that effect.

assan rekowski

Posts: 22
Nickname: haiaw
Registered: Sep, 2003

Re: GeneratingClasses and mappingFiles from database schema/ sql with ant/m Posted: Nov 25, 2005 4:03 AM
Reply to this message Reply
Thanks.
But my task is to do a script in MAVEN which would work like sql->hbm->Java class
Maybe u have some examples of just such script?

Flat View: This topic has 2 replies on 1 page
Topic: Socket Programming Previous Topic   Next Topic Topic: Importing classes

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use