-->
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.  [ 24 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Hibernate with middlegen; problems with Oracle db driver
PostPosted: Wed May 19, 2004 4:07 am 
Regular
Regular

Joined: Tue May 11, 2004 9:23 am
Posts: 69
Hi,

I'm running middlegen with ant and I have a Oracle database and want to middlegen to create both hbm.xml and java files if possible. But right now I can't get Middegen to find my oracle jdbc driver.

The driver I got today (working fine in Websphere) is classes12.zip but what I can find see in in build.xml and build.properties.sample middlegen only manages .jar files. Is anyone using classes12.jar?

Has anybody connected to oracle with middlegen and can help me?

build.xml
------------
Code:
<!DOCTYPE project [
    <!ENTITY database SYSTEM "file:./config/database/hsqldb.xml">
    <!ENTITY database SYSTEM "file:./config/database/oracle.xml">
   
    <!ENTITY ejb      SYSTEM "file:./config/ejb/jboss.xml">
    <!--ENTITY ejb      SYSTEM "file:./config/ejb/weblogic.xml"-->
    <!--ENTITY ejb      SYSTEM "file:./config/ejb/mvcsoft.xml"-->
]>



build.properties.sample
--------------------------'


Code:
#middlegen.skip=dummy
build.compiler=modern

#Tell Middlegen where weblogic.jar is located. Works with 6.1 and 7.0
#weblogic.jar=D:/bea/wlserver6.1/lib/weblogic.jar
weblogic.jar=D:/bea/weblogic700/server/lib/weblogic.jar

#Tell Middlegen where JBoss is located.
jboss.home=D:/jboss-3.0.0

#Tell Middlegen where to deploy the ear file.
deploy.dir=${jboss.home}/server/default/deploy
#deploy.dir=D:/bea/user_projects/ApplicationDomain/applications

#Tell Middlegen where MVCSoft is located.
mvcsoft.home=D:/persistence_mvcsoft

#Tell Middlegen where Oracle is located.
oracle.home=C:/OracleJDBC/Lib/classes12/oracle/jdbc
#Gui or not?
gui=true

# Middlegen is only bundled with JDBC drivers for HsqlDB, MySql and PostgreSQL.
# If you edit build.xml to use a different database, you should point
# out the location of the jar containing the driver here.

#McKoi
mckoi.home=D:/mckoi0.93
mckoidb.jar=${mckoi.home}/mckoidb.jar
mkjdbc.jar=${mckoi.home}/mkjdbc.jar
classes12.zip=${oracle.home}/classes12.zip


#uncomment this to run the compatibility test for a specific driver/db
#note that you might need to edit the script in order for your database
#to accept it. (e.g. mysql needs indexes and type=innodb after each table creation)
#this also requires that you have the middlegen sources
#database.script.file=../src/sql/relations.sql



Oracle.xml
-------------

<!-- =================================================================== -->
<!-- ant properties/targets for oracle 8/9 -->
<!-- note: this is not a proper xml file (there is no root element) -->
<!-- it is intended to be imported from a *real* xml file -->
<!-- =================================================================== -->

<!-- please set your Oracle-SID according to your needs -->

<property environment="env"/>

<property name="database.script.file" value="${src.dir}/sql/${name}-oracle.sql"/>
<!-- <property name="database.driver.file" value="${env.ORACLE_HOME}/jdbc/lib/classes12.jar"/> -->
<property name="database.driver.file" value="${env.ORACLE_HOME}/OracleJDBC/Lib/classes12/oracle/jdbc/classes12.zip"/>
<property name="database.driver.classpath" value="${database.driver.file}"/>
<property name="database.driver" value="oracle.jdbc.driver.OracleDriver"/>

<property name="database.url" value="jdbc:oracle:thin:@localhost:1521:<ORASID>"/>
<property name="database.userid" value=""/>
<property name="database.password" value=""/>
<property name="database.schema" value=""/>
<property name="database.catalog" value=""/>

<!--property name="jboss.datasource.mapping" value="Oracle7"/-->
<property name="jboss.datasource.mapping" value="Oracle8"/>
<!--property name="jboss.datasource.mapping" value="Oracle9i"/-->

Best regs

Johan


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 4:20 am 
Senior
Senior

Joined: Fri Nov 21, 2003 5:55 am
Posts: 155
Hello,


Your config seems good, I use it but with the Jar not zip maybe the problem come from it.
Please, show your error and the interesting part of build.xml


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 4:27 am 
Regular
Regular

Joined: Tue May 11, 2004 9:23 am
Posts: 69
Hey,

I assume the "Run Middlegen" ist the interesting part in build.xml. I've understood that that's where changes are made...hmm.


Code:
<!-- =================================================================== -->
   <!-- Run Middlegen                                                       -->
   <!-- =================================================================== -->
   <target
      name="middlegen"
      description="Run Middlegen"
      unless="middlegen.skip"
      depends="init,fail-if-no-xdoclet-1.2,check-driver-present,panic-if-driver-not-present"
   >
      <mkdir dir="${build.gen-src.dir}"/>

      <taskdef
         name="middlegen"
         classname="middlegen.MiddlegenTask"
         classpathref="lib.class.path"
      />
<!--
     <middlegen
         appname="${name}"
         prefsdir="${src.dir}"
         gui="${gui}"
         databaseurl="${database.url}"
         initialContextFactory="${java.naming.factory.initial}"
         providerURL="${java.naming.provider.url}"
         datasourceJNDIName="${datasource.jndi.name}"
         driver="${database.driver}"
         username="${database.userid}"
         password="${database.password}"
         schema="${database.schema}"
         catalog="${database.catalog}"
      >

-->
   <middlegen
            appname="${name}"
            prefsdir="${src.dir}"
            gui="${gui}"
            databaseurl="something"
            initialContextFactory="${java.naming.factory.initial}"
            providerURL="${java.naming.provider.url}"
            datasourceJNDIName="${datasource.jndi.name}"
            driver="oracle.jdbc.driver.OracleDriver"
            username="whatever"
            password="whatever"
            schema="database.schema"
            catalog="${database.catalog}"
      >


         <!--
         We can specify what tables we want EJBs generated for.
         If none are specified, EJBs will be generated for all tables.
         Comment out the <table> elements if you want to generate for all tables.
         Also note that table names are CASE SENSITIVE for certain databases,
         so on e.g. Oracle you should specify table names in upper case.

         The sequencename attribute is optional and will be used from
         the oraclesequence extension. If no sequencename is present
         it will be the name attribute suffixed by _SEQ.

         -->
         <!--table generate="true" name="persons" pktable="persons_pk"
                sequencename="my_persons_sequence" />
         <table generate="true" name="flights" pktable="flights_pk"/>
         <table name="reservations"/-->

         <!--
         If you want m:n relations, they must be specified like this.
         Note that tables declare in multiple locations must all have
         the same value of the generate attribute.
         -->
         <!--many2many>
            <tablea generate="true" name="persons"/>
            <jointable name="reservations" generate="false"/>
            <tableb generate="true" name="flights"/>
         </many2many-->

  <!--table name="PERSON" pktable="id" singular="person" plural="persons" />
  <table name="ADDRESS" pktable="id" singular="address" plural="addresses" />

<many2many>
  <tablea generate="true" name="PERSON" />
  <jointable name="EMPLOYMENT" generate="false" />
  <tableb generate="true" name="PERSON" />
</many2many-->

         <cmp20
            destination="${build.gen-src.dir}"
            package="${name}.ejb"
            interfacepackage="${name}.interfaces"
            jndiprefix="${unique.name}"
            pkclass="false"
            dataobject="false"
            valueobject="true"
            sessionfacade="true"
            viewtype="local"
            mergedir="${basedir}/src/middlegen"
            readonly="false"
            fkcmp="true"
            guid="true"
         >
            <!-- Let the EJBs use The portable Sequence Block PK generation pattern -->
            <sequenceblock
               blocksize="5"
               retrycount="2"
               table="SEQ_BLOCK"
            />

            <!--

            Alternatively to the sequenceblock you may use
            Oracle-Sequences if you have an Oracle RDBMS.
           
            You must use the table element in the middlegen-task if
            you want to provide the sequencename (see above). If you
            do not enter a sequencename the sequencename will be
            assumed to be like 'TABLE_NAME'_SEQ. (e.g. Table FOO will
            use the Sequence FOO_SEQ)

            Be sure that the datasource entry matches the entry from
            the ejbdoclet applicationserver element (e.g. <jboss/>)

            Additional attributes are interfacepackage and package. If
            these values are not provided they will be superseded by
            the plugin's attributes.

            -->
            <!--oraclesequence
               datasource="java:/OracleDS"
            /-->


            <!-- We can use predicates to specify what columns we want finders for -->
            <!--finders>
               <and>
                  <indexed/>
                  <notkey/>
               </and>
            </finders-->
           
            <!--
            EJB containers can be specified here. They add aditional
            features and perform additional validations. You don't have to
            add them, they just provide "goodies".
            -->
            <!--weblogic pkgen="VENDOR_SEQ" generatorName="my_sequence" keyCacheSize="20"/-->
            <weblogic/>
            <jboss/>

            <!-- options for mvcsoft listed in cmp20 docs -->
            <!--<mvcsoft/>-->
         </cmp20>
         
         <!-- generate som read-only beans too -->
         <!--cmp20
            name="cmp20_ro"
            destination="${build.gen-src.dir}"
            package="${name}.ejb"
            interfacepackage="${name}.interfaces"
            jndiprefix="${unique.name}"
            generatepk="false"
            dataobject="false"
            viewtype="local"
            mergedir="${basedir}/src/middlegen"
            readonly="true"
            fkcmp="true"
            suffix="RO"
         >
            <jboss/>
            <mvcsoft/>
         </cmp20-->

         <sunjdo10
            destination="${build.gen-src.dir}"
            package="${name}.jdo"
         />

         <html destination="${build.html.dir}">
            <!--
            We can override the plugin's templates
            by specifying the id of the original template
            and providing a new one from the file system.
           
            Uncomment the line below to see it in action.
            (This technique can be used for all plugins).
            -->
            <!--fileproducer
               id="single-table"
               template="${basedir}/src/templates/single-table.vm"
            /-->
         </html>

         <!--
         This illustrates the use of custom templates without the need to write
         a custom plugin. Just use the <plugin> task directly and specify as many
         <fileproducers> as you like. If the filename attribute contains a {0},
         one file will be generated per table, and the {0} will be substituted by
         the table name in the generated files. If there is no {0}, only one file
         will be generated. You can also narrow down the number of tables by
         explicitly specifying nested <table> elements. If you don't specify
         nested <table> elements, all tables will be used.
         -->
         <simple
            destination="${basedir}"
         >
            <fileproducer
               destination="${basedir}/build"
               filename="toto-{0}.txt"
               template="${basedir}/src/templates/simple.vm"
            >
               <table name="RESERVATIONS"/>
               <table name="PERSONS"/>
            </fileproducer>
         </simple>

         <!-- Plugins "under construction" -->
         <!--xmi
            destination="${build.xmi.dir}"
         /-->
         <struts
            destination="${build.gen-src.dir}"
            package="${name}.web.struts"
         >
            <jsp
               name="myjsp"
               destination="${build.gen-webui.dir}"
            />
         </struts>
         
         <hibernate
            destination="${build.gen-src.dir}"
            package="${name}.hibernate" javaTypeMapper="middlegen.plugins.hibernate.HibernateJavaTypeMapper"
         />
         

         
      </middlegen>

      <mkdir dir="${build.classes.dir}"/>
   </target>



Got the fault here:



BUILD FAILED
C:\Middlegen\middlegen-2.0-vo\samples\build.xml:217: middlegen.MiddlegenException: Couldn't load JDB
C driver oracle.jdbc.driver.OracleDriver. Make sure it's on your classpath.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 4:37 am 
Senior
Senior

Joined: Fri Nov 21, 2003 5:55 am
Posts: 155
In your target middlegen use this line
driver="${database.driver}" instead of driver=jdbc.....Oracle.Driver.



${database.driver}" reference the flag in your file oracle.xml


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 4:40 am 
Senior
Senior

Joined: Fri Nov 21, 2003 5:55 am
Posts: 155
subich wrote:
In your target middlegen use this line
driver="${database.driver}" instead of driver=jdbc.....Oracle.Driver.



${database.driver}" reference the flag in your file oracle.xml

Forget this old message

Verify that you add database.driver.classpath in your classpath
lib.class.path.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 4:45 am 
Regular
Regular

Joined: Tue May 11, 2004 9:23 am
Posts: 69
I don't understand. I shouldn't do this?

Quote:
In your target middlegen use this line
driver="${database.driver}" instead of driver=jdbc.....Oracle.Driver.


${database.driver}" reference the flag in your file oracle.xml



Secondly, where do I find the classpath? Should I point out the classes12.zip as an environmental variable?


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 4:50 am 
Regular
Regular

Joined: Tue May 11, 2004 9:23 am
Posts: 69
After added driver="${database.driver}" I got the following fault:

BUILD FAILED
C:\Middlegen\middlegen-2.0-vo\samples\build.xml:217: middlegen.MiddlegenException: Couldn't connect
to database: No suitable driver



Does it mean that classes12.zip doesn't work?


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 5:00 am 
Senior
Senior

Joined: Fri Nov 21, 2003 5:55 am
Posts: 155
I just try my application with classes12.zip and it's work, I think it's only a classpath driver problem

So... i your build.xml, you have

<taskdef
name="middlegen"
classname="middlegen.MiddlegenTask"
classpathref="lib.class.path"
/>

And verify you have something like that for lib.class.path at the top of your build.xml

<path id="lib.class.path">
<pathelement path="${database.driver.classpath}"/>
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
<fileset dir="${basedir}/lib/middlegen-lib">
<include name="*.jar"/>
</fileset>
</path>


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 5:14 am 
Regular
Regular

Joined: Tue May 11, 2004 9:23 am
Posts: 69
I had the to code parts you showed. I think it works now since it doesn't complain on the database or driver. Thanks a lot subich!

I'm just wondering....right now middlegen creates ejb and stuff. I tried to comment away <!ENTITY ejb SYSTEM "file:./config/ejb/jboss.xml"> but then middlegen compains on a lot of other stuff.


Code:
<!DOCTYPE project [
    <!ENTITY database SYSTEM "file:./config/database/hsqldb.xml">
    <!ENTITY database SYSTEM "file:./config/database/oracle.xml">
   
    <!ENTITY ejb      SYSTEM "file:./config/ejb/jboss.xml">
    <!--ENTITY ejb      SYSTEM "file:./config/ejb/weblogic.xml"-->
    <!--ENTITY ejb      SYSTEM "file:./config/ejb/mvcsoft.xml"-->
]>



Seems like the build.xml is written for the airline example or am I wrong? You see I got a database and just want to create the hbm.xml and java files.

Got any tip for configurating the build.xml? Do I have to rewrite a lot or what? For example I don't what to create any tables.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 5:29 am 
Senior
Senior

Joined: Fri Nov 21, 2003 5:55 am
Posts: 155
Ok fine if it's work.

So if you only want to generate XXX.hbm.xml, you can put only this

<!DOCTYPE project [
<!ENTITY database SYSTEM "file:./config/database/oracle.xml">
]>

and this for middlegen

<target name="middlegen"
description="Run Middlegen"
unless="middlegen.skip"
depends="init,fail-if-no-xdoclet-1.2,check-driver-present,panic-if-driver-not-present">
<mkdir dir="${build.gen-src.dir}"/>
<echo message="Class path = ${basedir}"/>
<taskdef name="middlegen" classname="middlegen.MiddlegenTask" classpathref="lib.class.path"/>
<middlegen appname="${name}"
prefsdir="${src.dir}"
gui="${gui}"
databaseurl="${database.url}"
initialContextFactory="${java.naming.factory.initial}"
providerURL="${java.naming.provider.url}"
datasourceJNDIName="${datasource.jndi.name}"
driver="${database.driver}"
username="${database.userid}"
password="${database.password}"
schema="${database.schema}"
catalog="${database.catalog}">

<table generate="true" name="USERS" pktable="SEQID"/>
<table generate="true" name="OPPORTUNITIES" pktable="SEQID"/>
<table generate="true" name="CONTRACT_TYPES" pktable="SEQID"/>
<table generate="true" name="DIPLOMAS" pktable="SEQID"/>
<table generate="true" name="STATUS" pktable="SEQID"/>
<table generate="true" name="EXPERIENCES" pktable="SEQID"/>
<table generate="true" name="FUNCTIONS" pktable="SEQID"/>
<table generate="true" name="DEPARTMENTS" pktable="SEQID"/>
<table generate="true" name="USERS" pktable="SEQID"/>
<table generate="true" name="SKILLS_CATEGORIES" pktable="SEQID"/>
<table generate="true" name="CANDIDATES" pktable="SEQID"/>
<table generate="true" name="LOCALIZATIONS" pktable="SEQID"/>
<table generate="true" name="SKILLS" pktable="SEQID"/>
<table generate="true" name="LANGUAGES" pktable="SEQID"/>
<table generate="true" name="FEEDBACK_TYPES" pktable="SEQID"/>
<table generate="true" name="LANGUAGE_CANDIDATES" pktable="CAN_SEQID, LAN_SEQID"/>
<table generate="true" name="FEEDBACK" pktable="SEQID"/>



<many2many>
<tablea generate="true" name="CANDIDATES" pktable="SEQID"/>
<jointable name="MOBILITIES" generate="false"/>
<tableb generate="true" name="LOCALIZATIONS" pktable="SEQID"/>
</many2many>
<many2many>
<tablea generate="true" name="CANDIDATES" pktable="SEQID"/>
<jointable name="CAND_SKILLS" generate="false"/>
<tableb generate="true" name="SKILLS" pktable="SEQID"/>
</many2many>

<hibernate destination="${config.dir}/sar/mapping"
package="com.mcstechnology.mcsrecrutement.valueobject"
genXDocletTags="false"
genIntergratedCompositeKeys="yes"
javaTypeMapper="middlegen.plugins.hibernate.HibernateJavaTypeMapper"/>
</middlegen>
<mkdir dir="${build.classes.dir}"/>
</target>


By default if you put nothing into the node table and many to many, all xml files for Oracle schema will be created.
But it's better to manage them and give the names of wich table you want to use and fot the many to many to.
You can delete all node for CMP20 ...


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 5:51 am 
Regular
Regular

Joined: Tue May 11, 2004 9:23 am
Posts: 69
Okey, I've tried to comment of but everytime I'm commenting away some new problem a arise and I comment that away. What's strange is that with out any "commenting away" it creates the files for airline example but not any files from my oracle database.

Is it more like I should add info about my tables in the build.xml so i tcreate files for it too. I thought it would do it automaitcally.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 5:57 am 
Senior
Senior

Joined: Fri Nov 21, 2003 5:55 am
Posts: 155
For your own database fill in these value fields

<property name="database.userid" value=""/>
<property name="database.password" value=""/>
<property name="database.schema" value=""/>
<property name="database.catalog" value=""/>


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 6:17 am 
Regular
Regular

Joined: Tue May 11, 2004 9:23 am
Posts: 69
I've filled in the 4 stuff in oracle.xml (not database.catalog cause I don't know what that one is).

I got 12 tables...

▪ ARTICLECOUNTRY_T
▪ ARTICLELANGUAGE_T
▪ CLOB_TEST1
▪ COUNTRY_T
▪ CUSTOMERORDERLINE_T
▪ CUSTOMERORDER_T
▪ CUSTOMER_T
▪ DELIVERYADDRESS_T
▪ ITEM_T
▪ KEYGENERATOR_T
▪ STORESTOCK_T
▪ STORE_T

...these are the ones I want xml-files for.

I


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 7:28 am 
Senior
Senior

Joined: Fri Nov 21, 2003 5:55 am
Posts: 155
Oracle catalog is the same as your schema.

Do you need ejb or only hbm.xml files?


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 8:01 am 
Regular
Regular

Joined: Tue May 11, 2004 9:23 am
Posts: 69
Okey, I need hbm.xml specially though if possible also java files...if it can generate that too.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 24 posts ]  Go to page 1, 2  Next

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.