|
|
Middlegen for HibernateMiddlegen - version 2.x http://boss.bekk.no/boss/middlegen/, with version 3.x moving to http://middlegen.codehaus.org/ open source tool.
What is Middlegen?Middlegen is an open source code generation framework that provides a general-purpose database-driven engine using various tools such as JDBC, Velocity, Ant and XDoclet.
What is it good for?The benefit of using Middlegen is that you can use an existing database design, optionally fine tune the settings, then Middlegen generates directly (or indirectly using additional tools and processes) all the repetitive, tedious to write code and configuration files for you.
What is the relationship to Hibernate?The Middlegen design includes a plug-in architecture which facilitates particular aspects of a target system. Existing plugins include, simple java classes, EJB, JDO and now (close to) complete support for Hibernate. The hibernate plugin focuses on the generation of the mapping configuration files. Hibernates' excellent native hbm2java tool can be used to generated the domain classes.
Where can I find it?The plugin has been initially created for the version 2.x series of Middlegen found at this project website. Feel free to ask questions on the mailing list (middlegen-user@lists.sourceforge.net) or under the Hibernate tools forum. The effort on version 3.x series of Middlegen is currently the primary focus of the core Middlegen development team and as such the Hibernate plugin will definately be ported to the new platform. The plugin status, some source and patches are to be found in the Middlegen JIRA bug tracking system [until the next beta is release (expected to be V3.0b1)]. Middlegen 2.x source in located on Sourceforge in CVS head (from the vo [final]) release (plugin release 4). While Middlegen 3.x is being created, I have released a preview package(s) on the Hibernate sourceforge files site to allow all users to get started using the plugin with minimal effort. The package also demonstrates one possible way to setup a development environment. Once Middlegen 3.x beta is released then the v2.x package(s) will become redundant.
How do I use Middlegen?Middlegen provides an Ant task from which to initiate the code generation for the target platforms. The task can include more than a single target, eg, Hibernate and EJB target. The following task is configured for the Hibernate plugin only.
<!-- ============================================================== -->
<!-- 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}"/>
<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}"
>
<!-- Plugins -->
<hibernate
destination="${build.gen-src.dir}"
package="${name}.hibernate"
javaTypeMapper="middlegen.plugins.hibernate.HibernateJavaTypeMapper"
/>
</middlegen>
<mkdir dir="${build.classes.dir}"/>
</target>
The majority of the task options involves setting up the data source. Fine-tuning of the generation process is provide primarily through a Java Swing based GUI. This is activated when the gui option in the Middlegen Ant task is true. Middlegen has a sample application that can provide a guide for your own project adoption of Middlegen. Middlgen by default creates Hibernate 2.x mapping files. Middlgen 2.2 introduced the option of creating Hibernate 3.0 mapping files by using the version element. For example;
....
<!-- Plugins -->
<hibernate
destination="${build.gen-src.dir}"
package="${name}.hibernate"
javaTypeMapper="middlegen.plugins.hibernate.HibernateJavaTypeMapper"
version="3.0"
/>
...
Note: hibernate tools package has vastly improved and is worth considering as an alternative for hibernate 3.x features.
What is generated by the Hibernate plugin?The Hibernate plugin generates the XML mapping document for Hibernate 2 only (This can be easily changed with additional templates). The motivation for this that a single output stream is easier to be maintained. Following is an example of the a mapping file generated by the plugin.
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="airline.hibernate.Flight"
table="flights"
schema="fdgdf"
proxy="airline.hibernate.Flight"
>
<meta attribute="implements">net.sf.hibernate.Lifecycle</meta>
<meta attribute="scope-class">protected</meta>
<id
name="flightId"
type="java.lang.Long"
column="flight_id"
>
<generator class="assigned" />
</id>
<timestamp
name="departureUtc"
column="departure_utc"
/>
<property
name="name"
type="java.lang.String"
column="name"
insert="false"
not-null="true"
length="32"
/>
<property
name="arrivalUtc"
type="java.sql.Timestamp"
column="arrival_utc"
not-null="true"
>
<meta attribute="field-description">
This is a field description for the property
</meta>
<meta attribute="scope-get">protected</meta>
</property>
<!-- associations -->
<!-- bi-directional one-to-many association to Reservation -->
<set
name="reservations"
lazy="true"
inverse="true"
>
<key>
<column name="flight_id_fk" />
</key>
<one-to-many
class="airline.hibernate.Reservation"
/>
</set>
</class>
</hibernate-mapping>
From release 3 of the plugin XDoclet markup can be generated using meta tags in the hbm mapping document. In addition, compound keys can be generated as internal rather than the default (and recommended) external class. These options are set using the Ant script. For example XDoclet generation:
<hibernate
destination="${build.gen-src.dir}"
package="${name}.hibernate"
genXDocletTags="true"
/>
The internal generation of composite keys can be selected as below.
<hibernateasdf
destinatasdfffasfddfssdfion="${build.gen-src.dir}"
package="${name}.hibernate"
genIntergratedCompositeKeys="true"
/>
They can be combined. The default is false for both options thus you are not required to included these options if false is appropriate. NOTE: Post hibernate 2.1beta6 DTD is required to validate correctly for all possible XDoclet meta tags. From release 4 of the plugin custom Java type mapper can be created and hence applied during the initial type allocation phase and the resulting selection used during the generation phase(s). Any mapping that has been previously selected or fine tuned through the use of the GUI will not be modified by the mapper. Release 4 includes an improved JavaMapper and it is recommended this is used rather than the Middlegen core default selection. For example to install the standard custom java mapper:
<hibernate
destination="${build.gen-src.dir}"
package="${name}.hibernate"
javaTypeMapper="middlegen.plugins.hibernate.HibernateJavaTypeMapper"
/>
To create your own custom Java type mapper you just need to extend the middlegen.plugins.hibernate.interfaces.JavaTypeMapper interface
public interface JavaTypeMapper {
/**
* Gets the PreferredJavaType attribute of the JavaTypeMapper object
*/
public String getPreferredJavaType(JavaColumn column);
}
and reference the class in the Ant script under the hibernate plugin tag. Refer to the HibernateJavaTypeMapper and the documentation as an example. The excellent native Hibernate hbm2java tool can be used (optionally through Ant) to generated the Java domain objects. In fact, the Hibernate plugin employs the meta tags to provide domain code generation preferences designed for hbm2java processing. Here is the Ant task required to generate the POJOs using hbm2java.
<target name="hbm2java"
description="Generate .java from .hbm files.">
<hbm2java config="${build.dir}/hibernate.cfg.xml"
output="${gensrc.dir}"
>
<fileset dir="${gensrc.dir}">
<include name="**/*.hbm.xml"/>
</fileset>
</hbm2java>
</target>
Currently setting the cascading options on the relationships is no possible (will be in the near future) so you can post process the hbm files to select the appropriate setting. The following Ant target illustrates one approach using the replaceregex Ant task.
<target name="hbm2java"
description="Generate .java from .hbm files." depends="init">
<property name="hbm.dir" location="${build.generate.dir}/com/mappings/"/>
<replaceregexp
match='cascade="none"'
replace='cascade="all"'
byline="true">
<fileset dir="${hbm.dir}" includes="MapRequest.hbm.xml,MapRun.hbm.xml" />
</replaceregexp>
<mkdir dir="${build.generate.dir}"/>
<taskdef
name="hbm2java"
classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask"
classpathref="hibernate.classpath"
/>
<hbm2java output="${build.generate.dir}" classpathref="hibernate.classpath">
<fileset dir="${build.generate.dir}">
<include name="**/*.hbm.xml"/>
</fileset>
</hbm2java>
</target>
The process can be managed using as in a single step by adding a dependency on the hbm2java target on the Middlegen target. This will automatically generate the code as soon as you have finished with Middlegen.
Hints and tips1) Large datasets and memory problems: Try the following technique to tell the JVM to allocate more memory.
export ANT_OPTS=-Xmx512M
ant middlegen
Feature set of the Hibernate PluginThe plugin is designed to be the best Middlegen plugin :-) and provide a feature full solution for those that like to (or must) work using a bottom up strategy. The plugin provides:
- The bulk of the options for both direct Hibernate mapping attributes and hbm2java meta attributes.
- Appropriate GUI enhancements (See images in Middlegen JIRA). This allows easily selecting the various options and using the faciltiies provided.
- Storing the GUI state for both the Table and Columns so that it is correctly restored each fine tuning or code generation session.
- Full support for setting attributes across multiply selected columns (I don't allow multiple select for some properties, eg, the gen-property meta attribute).
- Added silent unique mapping attribute (not a part of the GUI).
- Full Relationship support (through foreign keys), eg, one-to-one, one-to-many, many-to-one, many-to-many with either uni- and bi-directional associations. Note: One-to-one with foreign keys requires hibenate 2.1.
- Compound key support. Method uses an external Java class to hold the key fields.
- No primary key tables are generated a single compound key property.
- XDoclet markup for POJO generation to allow prototyping for top-to-bottom development.
- Generate the hbm file appropriately (decided to not generate any optional XML attributes if it is not required and setting is equal to the default or an empty value).
- Custom Java type mapper plugin provider facility (start of Plugins for this Plugin).
The areas I have not implemented (as yet) include: polymorphism (and associate items), generated class name meta attribute, meta finder method and meta session method, or inheritance of meta data options (This is likely to be asked for in the future (assuming it gets a user base) but at this stage it will overload the GUI and I did not want to get to complicated).
What about Hibernates' ddl2hbm tool?The ddl2hbm tool formally known as the Reverse Engineering Tool targets the same functionality as the Hibernate Middlegen plugin. Non-core systems are being moved into external jar packages. This includes ddl2hbm which is being moved to the HibernateExt/tools CVS repository and tools jar. Hibernates' core goal is to do one thing very well, thus over time, it is likely that the Middlegen plugin will be the primary tool for generating hibernate mapping's directly from JDBC data sources. --David David, how did you get middlegen to create the timestamp tag? <timestamp name="departureUtc" column="departure_utc" /> Add this in your node column in your preference file : <entry key="columnspecialty" value="version" />
| Middlegen example on hibernate page @ sourceforge
| 14 Oct 2003, 21:42
| seanoc5
|
In case anyone else had trouble getting started with middlegen, there is
a handy download at sourceforge:
http://prdownloads.sourceforge.net/hibernate/?sort_by=date&sort=desc
(also linked from the downloads section) of the hibernate site.
It is pretty close to plug and play, and has helped me a great deal with
understanding middlegen.
Thanks to all involved.
|
| |
| would you like to help me?
| 10 Nov 2003, 04:17
| hudh
|
hi,
I set up the middlegen-hibernate-r2 and configure the buid.xml and
oracle.xml and then execute the ant command,but exception out is there
is no tables .but i am sure there is lots of tables with my oracle.xml
configuration.
Doesn't It support oracle generation?
|
| |
| Making middlegen conditional
| 06 Jan 2004, 21:33
| craigduncan
|
I am using middlegen and hibernate to generate hbm.xml files and java
files from an existing database. My ant script runs middlegen and all
the output files from that process are written to the build dir.
Consequently an "ant clean" will remove all that generated code. I
would like to keep this behaviour as that is what you would expect a
clean to do. What I want to do is skip the middlgen target if the
database has not changed. Any suggestions on how to do this? I have
looked at the ant "uptodate" task but I can't see how to effectively use
that.
I noticed in the example above there is a unless="middlegen.skip" and
thought maybe you have figured out a way to do what I want to do.
Thanks for any input.
Craig Duncan
|
| |
| Re: Making middlegen conditional
| 09 Jan 2004, 13:38
| david
|
On 06 Jan 2004 21:33, craigduncan wrote:
>I am using middlegen and hibernate to generate hbm.xml files and java
>files from an existing database. My ant script runs middlegen and all
>the output files from that process are written to the build dir.
>Consequently an "ant clean" will remove all that generated code. I
>would like to keep this behaviour as that is what you would expect a
>clean to do. What I want to do is skip the middlgen target if the
>database has not changed. Any suggestions on how to do this? I have
>looked at the ant "uptodate" task but I can't see how to effectively
use
>that.
>I noticed in the example above there is a unless="middlegen.skip" and
>thought maybe you have figured out a way to do what I want to do.
>Thanks for any input.
>Craig Duncan
How you detect the database has changed is difficult. If you can just
set the proerty and your done. If you cannot, you would know as a
developer (maybe), so you can set the property on the Ant command line
prepared for processing the target.
|
| |
| MySQL
| 11 Jan 2004, 11:35
| twan
|
(using middlegen preview downloaded from hibernate sourceforge;
Middlegen-Hibernate-r4.zip)
When using MySQL the relations of the airline example is not detected.
As a solution you should download middlegen from the middlegen website
and extract the "mysql-connector-java-3.0.0-beta-bin.jar" from the
archive and put that into the /lib/ directory. When you do that
relations are getting detected.
|
| |
| Middlegen and DB2 !!!
| 26 Feb 2004, 13:37
| ernani
|
Seems that the developers from Middlegen does not seem to reply some
questions...
I can't get middlegen to work with db2 and to generate my mapping
files for hibernate... The problem is on the driver that for some
reason does not work...
Does anybody have a clue on this?
|
| |
| MySQL Relationships Require InnoDB Tables
| 10 Mar 2004, 06:49
| wiverson
|
You must use InnoDB tables (and have the foreign keys set) for Middlegen
to pick up the relationships.
If you already have MyISAM tables, see...
http://www.mysql.com/doc/en/Converting_tables_to_InnoDB.html
I was able to pick up relationships using
mysql-connector-java-3.0.10-stable-bin.jar.
|
| |
| Middlegen and DB2 !!!
| 11 Mar 2004, 16:15
| ChrisR
|
ernani,
Your \config\database\db2.xml file should look something like the
following. I have DB2 installed to c:\sqllib.
<!--
=================================================================== -->
<!-- ant properties/targets for IBM
DB2 -->
<!-- note: this is not a proper xml file (there is no root
element) -->
<!-- it is intended to be imported from a *real* xml
file -->
<!--
=================================================================== -->
<property name="sqllib.home" value="C:/sqllib"/>
<property name="database.script.file"
value="${src.dir}/sql/${name}-db2.sql"/>
<property name="database.driver.file"
value="${sqllib.home}/java/db2java.zip"/>
<property name="database.driver.classpath"
value="${database.driver.file}"/>
<property name="database.driver"
value="COM.ibm.db2.jdbc.app.DB2Driver"/>
<property name="database.url"
value="jdbc:db2:SAMPLE"/>
<property name="database.userid" value="userid"/>
<property name="database.password" value="password"/>
<property name="database.schema" value="CLEX"/>
<property name="database.catalog" value=""/>
Your build.xml should contain the following...
<!DOCTYPE project [
<!ENTITY database SYSTEM "file:./config/database/db2.xml">
]>
See if those work for you
Cheers
Chris
|
| |
| Re: Middlegen and DB2 !!!
| 18 Mar 2004, 01:01
| cpalit
|
There is one other thing to keep in mind with the Hibernate plugin for
Middlegen. In the build.xml file, on roughly line 145, in
the "middlegen" target, you may need to modify these lines:
schema="${database.schema}"
catalog="${database.catalog}"
I had to delete the "catalog=..." line before I could get things
working with a DB2400 database. It seems that even if this property is
empty, passing it as a parameter may cause an error that middlegen
cannot find any tables. (The forums mention you may need to remove one
or both the lines to get things working). Beyond following Chris'
suggestion, adding a few "<table..." tags and tweaking the default
generated package names, it seems to be working for me.
|
| |
| middlegen-hibernate-r2
| 02 Apr 2004, 09:37
| Acco Lade
|
I downloaded the package and ran it against a mysql database, and
well, how do I get my .java files? :-)
I do see my relationships and a bunch of .hbm.xml files, but nothing
else.
Did I miss something?
Thanks,
Acco
|
| |
| Re: middlegen-hibernate-r2
| 02 Apr 2004, 09:39
| Acco Lade
|
On 02 Apr 2004 09:37, Acco Lade wrote:
>I downloaded the package and ran it against a mysql database, and
>well, how do I get my .java files? :-)
>I do see my relationships and a bunch of .hbm.xml files, but nothing
>else.
>Did I miss something?
>Thanks,
>Acco
Correction: I used version R4 and the latest xyz-11 JDBC connector
from mysql.com.
|
| |
| Re: middlegen-hibernate-r2
| 04 May 2004, 06:10
| kas
|
On 02 Apr 2004 09:39, Acco Lade wrote:
>On 02 Apr 2004 09:37, Acco Lade wrote:
>>I downloaded the package and ran it against a mysql database, and
>>well, how do I get my .java files? :-)
>>I do see my relationships and a bunch of .hbm.xml files, but nothing
>>else.
>>Did I miss something?
>>Thanks,
>>Acco
>Correction: I used version R4 and the latest xyz-11 JDBC connector
>from mysql.
One way to get it working is to:
1. add target hbm2java(I copied it from the Middlegen build.xml) to
your build.xml.
2. modify target compile-hibernate by adding hbm2java to the depends
(see below).
3. add any missing .jars from Middlegen. To download Middlegen you
can go to: http://sourceforge.net/project/showfiles.php?group_id=36044
then unzip the files. I was in a rush so I copied the files in the
Middlegen lib folder to your lib folder. You may only need to add the
hibernate jars ??
<!-- ============================================================= -->
<!-- Run hbm2java -->
<!-- ============================================================= -->
<target name="hbm2java" depends="middlegen"
description="Generate .java from .hbm files.">
<taskdef
name="hbm2java"
classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask"
classpathref="lib.class.path"
/>
<hbm2java output="${build.gen-src.dir}">
<fileset dir="${build.gen-src.dir}">
<include name="**/*.hbm.xml"/>
</fileset>
</hbm2java>
</target>
---------------------------------------------------
<!-- ============================================================= -->
<!-- Compile business logic (hibernate) -->
<!-- ============================================================ -->
<target name="compile-hibernate" depends="middlegen, hbm2java"
description="Compile hibernate Business Domain Model">
...
|
| |
| Re: middlegen-hibernate-r2
| 08 May 2004, 02:56
| srirang
|
I can't seem to get middlegen-hibernate-r4 to work with db2. My
build.xml has...
<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}"
>
As suggested in the previous posts, I tried removing the catalog, then
schema, then both. No luck. If I remove both, I can see it scanning each
table and shows a message saying that it did not generate any mapping
since the schema is not specified. Like...
[middlegen] (middlegen.MiddlegenPopulator 929 ) The table named
EXPENSETYPE was found in the schema named "DBA". However, Middlegen was
not configured to look for tables in a specific schema. You should
consider specifying schema="DBA" in the middlegen task.
But if I specify schema as "DBA", I get
Middlegen successfully connected to the database, but couldn't find any
tables. Perhaps the specified schema or catalog is wrong? -Or maybe
there aren't any tables in the database at all?
|
| |
| Re: middlegen-hibernate-r2
| 29 May 2004, 13:35
| david
|
I cannot help other than pointing out that Middlegen is using a
standard JDBC connection. Once you have the appropriate configuration
then its up to the JDBC driver to provide the meta data about the
database. In your case, your tables are likely to not be under the DBA
schema. Ask your DBA to tell you the owner of the tables.
|
| |
| Filter on which tables to map
| 08 Jun 2004, 19:09
| alu
|
Does anyone know to make middlegen to read in subset of tables in a
schema? I only want to map new tables.
Middlegen tried to read in all tables in my schema. It takes forever
to finish. As of writing this, it is still running!
|
| |
| Re: Filter on which tables to map
| 10 Jun 2004, 20:16
| decairn
|
On 08 Jun 2004 19:09, alu wrote:
>Does anyone know to make middlegen to read in subset of tables in a
>schema? I only want to map new tables.
>Middlegen tried to read in all tables in my schema. It takes forever
>to finish. As of writing this, it is still running!
It's possible to specify table names, but it's also ugly. See the
Middlegen site documentation on the ant target options.
We run it on a database with 500+ tables, takes 5 minutes to complete
using the full catalogue and passing it through hbm2java. With a
properly defined ant target structure this is only done once and the
output is sent to a jar in a dependency list. Subsequent compiles
ignore it and go straight to compiling application code.
|
| |
| Re: middlegen-hibernate-r2
| 22 Jun 2004, 20:25
| dfreire
|
Hi,
I solved this problem by removing the
schema="${database.schema}
catalog="${database.catalog}
lines from the build.xml file.
After this, everything started to work as expected.
|
| |
| Re: MySQL Relationships Require InnoDB Tables
| 27 Jul 2004, 19:41
| mxc4
|
On 10 Mar 2004 06:49, wiverson wrote:
>You must use InnoDB tables (and have the foreign keys set) for Middlegen
>to pick up the relationships.
>If you already have MyISAM tables, see...
>http://www.mysql.com/doc/en/Converting_tables_to_InnoDB.html
>I was able to pick up relationships using
>mysql-connector-java-3.0.10-stable-bin.jar.
I have the 3.0.14 version of this driver and still cannot pick up the
relationships. I know its not the driver as the eclipse plugin Hibernate
Synchroniser can pick up the relationships with this driver.
Is there some sort of option I am supposed to pass to the ant script to
pick up the relationships?
|
| |
| middlegen.MiddlegenException
| 12 Aug 2004, 22:32
| ayush
|
I'm trying to run middlegen against an oracle database. It does
connect to the db and finds the table in question but I get the
following message:
middlegen.MiddlegenException: Wow! Synonym DWPTD not found. How can it
happen?
Anyone knows what this means?
- ayush
|
| |
| Sequence Number Name Generation
| 13 Aug 2004, 16:58
| jasonvanbrackel
|
Can the middlegen plugin do Sequence name generation. I'm using the
plugin with Postgresql which creats it's sequences in the form
<tablename>_<idcolumnname>_seq. As of now i'm editing the structure in
middlegen to make the appropriate tables use sequence key generation and
manually type in the sequence name for each table. Is there a way I can
get middlegen to do that for me?
|
| |
| JavaTypeMapper PB
| 17 Aug 2004, 11:38
| ctof
|
I try to define my own JavaTypeMapper.
i set the value of my class to the property "javaTypeMapper" in the
hibernate section of my ant file.
then i start middlengen via ant and it seems that my mapper is never call.
more exactly, the constructor is called, but the method
"getPreferredJavaType" is never called
any idea ?
thx in advance
Christophe
|
| |
| Does Middlegen-Hibernate-r3 work with Pointbase?
| 19 Aug 2004, 19:10
| jeffcaz
|
When I use the build.xml file, I can create the tables and see them in
Pointbase, but the middlegen task fails, saying the tables aren't
there!!! Here are my Pointbase-specific property settings. I tried it
with and without the schema and catalog settings:
<property environment="env"/>
<property name="database.script.file"
value="${src.dir}/sql/${name}-pointbase.sql"/>
<property name="database.driver.file"
value="C:/sftwTools/pointbase/lib/pbclient44.jar"/>
<property name="database.driver.classpath"
value="${database.driver.file}"/>
<property name="database.driver"
value="com.pointbase.jdbc.jdbcUniversalDriver"/>
<property name="database.url"
value="jdbc:pointbase:server://localhost:9093/workshop"/>
<property name="database.userid" value="weblogic"/>
<property name="database.password" value="weblogic"/>
<property name="database.schema" value=""/>
<property name="database.catalog" value=""/>
<property name="jboss.datasource.mapping" value="Pointbase"/>
C:\sftwTools\Middlegen-Hibernate-r3>ant middlegen
Buildfile: build.xml
init:
fail-if-no-xdoclet-1.2:
check-driver-present:
panic-if-driver-not-present:
middlegen:
[echo] Class path = C:\sftwTools\Middlegen-Hibernate-r3
[middlegen] Database URL:jdbc:pointbase:server://localhost:9093/workshop
BUILD FAILED
C:\sftwTools\Middlegen-Hibernate-r3\build.xml:130:
middlegen.MiddlegenException:
The database doesn't have any table named weblogic.PERSONS. Please
make sure t
he table exists. Also note that some databases are case sensitive.
Total time: 1 second
C:\sftwTools\Middlegen-Hibernate-r3>
What am I doing wrong?
|
| |
| changing class-/attribute names ?!?
| 23 Aug 2004, 16:08
| CaveDiver
|
Hi all,
does anyone know how to change class-/attributes-names in the
middlegen UI ...
I've a legacy model to map which resides in an Oracle 9iR2 instance.
Table and Relationship detection is quite fine ...
The GUI shows up, I can manipulate relation-cardinality, I can change
almost all settings of Tables and Columns, except the names of the
java elements, which will be described and later on generated via
hbm2java ...
any hints are welcome!
Thx in advance
K:) Unger
klaus (at) ungers-online (dot) com
|
| |
| Re: JavaTypeMapper PB
| 23 Aug 2004, 18:57
| drosenbaum
|
On 17 Aug 04 11:38, ctof wrote:
>I try to define my own JavaTypeMapper.
>i set the value of my class to the property "javaTypeMapper" in the
>hibernate section of my ant file.
>then i start middlengen via ant and it seems that my mapper is never
call.
>more exactly, the constructor is called, but the method
>"getPreferredJavaType" is never called
>any idea ?
>thx in advance
>Christophe
As stated in the Hibernate Middlegen doc, the only time the
javaTypeMapper is called is the first time a new table is mapped. All
subsequent times the saved types are used and the mapper is not called
again.
Perhaps delete your prefs file to "fool" middlegen into thinking this
is the first time.
Daniel
|
| |
| Many-to-Many relationships - Mysql 4.1
| 15 Dec 2004, 15:32
| vivekvik
|
Hey,
ive been using middlegen to generate my mapping files. It works
great. It generates a mapping for all the tables in my schema
(approximately 20 tables) . Except when I added the following
<many2many>
<tablea generate="true" name="MERCHANTS" />
<jointable name="GROUPS_MERCHANTS" generate="false" />
<tableb generate="true" name="GROUPS" />
</many2many>
After I added this many-to-many restraint, all the other tables in my
schema (except groups and merchants) disappeared. The middlegen view
now only shows 2 tables!! This is what my ant task looks like:
<target
name="mymiddlegen"
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}"
>
<many2many>
<tablea generate="true" name="MERCHANTS" />
<jointable name="GROUPS_MERCHANTS" generate="false" />
<tableb generate="true" name="GROUPS" />
</many2many>
<!-- Plugins -->
<hibernate
destination="${build.gen-src.dir}"
package="${name}.hibernate"
javaTypeMapper="middlegen.plugins.hibernate.HibernateJavaTypeMapper"
/>
</middlegen>
<mkdir dir="${build.classes.dir}"/>
</target>
Any ideas?
|
| |
| Re: Many-to-Many relationships - Mysql 4.1
| 21 Dec 2004, 15:03
| gastaldi
|
Hi,
You have to specify all the other tables, otherwise middlegen will
generate code only for what you have specified.
On 15 Dec 2004 15:32, vivekvik wrote:
>After I added this many-to-many restraint, all the other tables in my
>schema (except groups and merchants) disappeared. The middlegen view
>now only shows 2 tables!! This is what my ant task looks like:
<table name="table_1"/>
<table name="table_2"/>
> <many2many>
> <tablea generate="true" name="MERCHANTS" />
> <jointable name="GROUPS_MERCHANTS" generate="false" />
> <tableb generate="true" name="GROUPS" />
> </many2many>
This way works for me.
|
| |
| (sorry, but) Could this be Simplified?
| 21 Dec 2004, 18:14
| eeverman
|
I definitely appreciate everyone's work here, but not being a regular user
of Ant or Middlegen, this is an uphill climb. There have been two
projects now where I've thought, "I'll try Middlegen w/ Hibernate", only
to revert back to hand-coding the XML files.
(I think) all the pieces are there - couldn't this just be a big
executable jar file with an adjacent folder to place jdbc drivers in?
Download the jar, copy your JDBC drivers to the folder, double click, type
in connection info or browse to a previously saved profile. Man, would
that make life easy.
Just thinking outloud...
|
| |
| standardGeneratorScheme does not work
| 06 Jan 2005, 14:47
| ipolevoy
|
I use middlegen 2.1.
I need to change the generator class fron default
"assigned" to another value, for instance "native".
The Ant tag looks like this:
<hibernate standardGeneratorScheme="native" destination="${src.dir}"
package="${target.package}"/>
My output files are still generated with the "assigned" class
regardless what value I provide in the build script:
<generator class="assigned" />
Please, help!
|
| |
| Re: standardGeneratorScheme does not work
| 11 Jan 2005, 02:51
| Geoff Clitheroe
|
On 06 Jan 2005 14:47, ipolevoy wrote:
>I use middlegen 2.1.
>I need to change the generator class fron default
>"assigned" to another value, for instance "native".
>The Ant tag looks like this:
><hibernate standardGeneratorScheme="native" destination="${src.dir}"
>package="${target.package}"/>
>My output files are still generated with the "assigned" class
>regardless what value I provide in the build script:
><generator class="assigned" />
>Please, help!
I used Middlegen-Hibernate-r5 and the middlegen-hibernate-plugin-2.1.jar
from middlegen-2.1 and it works:
<hibernate
destination="${build.gen-src.dir}"
package="${name}.hibernate"
standardGeneratorScheme="sequence"
standardGeneratorArg="{0}_SEQ"
genXDocletTags="false"
javaTypeMapper="middlegen.plugins.hibernate.HibernateJavaTypeMapper"
/>
gives output like:
<generator class="sequence">
<param name="sequence">MARK_SEQ</param>
</generator>
|
| |
| About Type Mapper in Oracle
| 07 Apr 2005, 00:22
| ojik
|
Hibernate version: 2.0
Middlegen-Hibernate version: R-5
Name and version of the database you are using:Oracle 9i
The generated SQL (show_sql=true):True
Hi,.. I Just got some problem from XBM Generated by Middlegen,
In the oracle table description look like this :
SQL> desc systlogin;
Name Null? Type
----------------------------------------- -------- --------------------
-------
SYSTLOGIN_PK NOT NULL NUMBER(38)
SYSTROLE_FK NUMBER(38)
CUSTOMER_FK NUMBER(38)
LOGINID NOT NULL VARCHAR2(10)
NAMA VARCHAR2(50)
ATASAN NUMBER(38)
PASSWORD VARCHAR2(20)
LANGUAGE VARCHAR2(2)
Look at this,..
SYSTLOGIN_PK NOT NULL NUMBER(38) <--- its was Integer in Oracle PL/SQL
The Question is : WHY everytime i try to generate XBM from this table
its produce UNEXPECTED type of Data, Middelegen will produce XBM type
data to BIGDECIMAL..In this case i want Middlegen to produce
SYSTLOGIN_PK type data to INTEGER
Systlogin.xbm.xml similar look like this :
<class
name="com.latih.db.Systlogin"
table="SYSTLOGIN"
>
<id
name="systloginPk"
type="java.math.BigDecimal"
column="SYSTLOGIN_PK"
>
<generator class="native" />
</id>
Anyone can figure me out ? Thanks,..
|
| |
| Re: Filter on which tables to map
| 11 May 2005, 07:21
| PG
|
On 10 Jun 2004 20:16, decairn wrote:
>On 08 Jun 2004 19:09, alu wrote:
>>Does anyone know to make middlegen to read in subset of tables in a
>>schema? I only want to map new tables.
>>Middlegen tried to read in all tables in my schema. It takes forever
>>to finish. As of writing this, it is still running!
>It's possible to specify table names, but it's also ugly. See the
>Middlegen site documentation on the ant target options.
>We run it on a database with 500+ tables, takes 5 minutes to complete
>using the full catalogue and passing it through hbm2java. With a
>properly defined ant target structure this is only done once and the
>output is sent to a jar in a dependency list. Subsequent compiles
>ignore it and go straight to compiling application code.
Hi decairn,
You wrote that it takes only 5 minutes to complete on a database with
500+ tables.
In my setup, it took 224 minutes to generate the xml and java files
for ONE table (with 40 columns).
What is your secret ?
What is critical in the setup to get your kind op performance ?
Thanks,
PG
|
| |
| Re: middlegen.MiddlegenException
| 09 Sep 2005, 10:24
| random_joe
|
POST QUESTIONS ON THE FORUM! COMMENTS HERE SHOULD ADD VALUE TO THE PAGE!
!On 12 Aug 2004 22:32, ayush wrote:
>I'm trying to run middlegen against an oracle database. It does
>connect to the db and finds the table in question but I get the
>following message:
>middlegen.MiddlegenException: Wow! Synonym DWPTD not found. How can it
>happen?
>Anyone knows what this means?
>- ayush
I've just come across this and I suspect it might be a small bug in
middlegen. If you look at getSynonymOwner() on MiddlegenPopulator.java,
the SQL is as follows:
select table_owner from sys.all_synonyms where table_name=? and owner=?
PreparedStatement variables are set as follows:
ps.setString(1, synonymName);
ps.setString(2, _schema);
Now, the structure of the oracle table sys.all_synonyms looks like this:
SQL> desc sys.all_synonyms;
Name Null? Type
----------------------------------------- ------- --------
OWNER NOT NULL VARCHAR2(30)
SYNONYM_NAME NOT NULL VARCHAR2(30)
TABLE_OWNER VARCHAR2(30)
TABLE_NAME NOT NULL VARCHAR2(30)
DB_LINK VARCHAR2(128)
So, looking at the method, it appears that the idea is to get the
synonym owner given the SYNONYM_name (and NOT the table_name). This
implies the SQL ought to read:
select table_owner from sys.all_synonyms where synonym_name=? and owner=?
I've only just spotted this (in my copy of the middlegen 2.1 source) so
I'm not sure if this is the crux of the matter. Hope it helps
Joe
|
| |
| Re: standardGeneratorScheme does not work
| 22 Sep 2005, 08:42
| stefanm
|
Note that you only set the standard preference with this setting.
This means, that as soon as you have a middlegen properties file, the
setting will be saved in this file and the standardGeneratorScheme will
be ignored.
Simply delete your properties file, then it will work.
cheers
Stefan
PS Unfortunately, only standard Hibernate ID generators are supported, I
did not manage do set a class that I have written as standard generator...
|
| |
| Re: standardGeneratorScheme does not work
| 22 Sep 2005, 11:32
| stefanm
|
POST QUESTIONS ON THE FORUM! COMMENTS HERE SHOULD ADD VALUE TO THE
PAGE!I now found out how you can make Middlegen use any Java class as a
generator. Simply add the class's name to both of the following attributes:
standardGeneratorScheme
standardGeneratorArg
e.g.:
<hibernate
destination="${gensrc.basedir}"
package="${gensrc.package}"
standardGeneratorScheme="at.xxx.TableIdGenerator"
standardGeneratorArg="at.xxx.TableIdGenerator"
javaTypeMapper="middlegen.plugins.hibernate.HibernateJavaTypeMapper"
genXDocletTags="true"/>
Note that as soon as you change any value in middlegen's key generator
drop-down box, it will never again use your owb Java class (unless you
edit the properties file)
|
| |
| Middlegen timestamp/version setup? (attn: David)
| 17 Oct 2005, 12:12
| fisherv
|
I am trying to implement Optimistic Locking via Middlegen IDE with JBoss
4.0.2 and Hibernate 3.0.5.
I saw this tidbit in the original text of this forum:
------------------------------------------------------------
David, how did you get middlegen to create the timestamp tag?
<timestamp name="departureUtc" column="departure_utc" />
Add this in your node column in your preference file :
<entry key="columnspecialty" value="version" />
------------------------------------------------------------
Could someone let me know to which "preference file" we should add the
<entry.../> line mentioned above?
Maybe a sample section of the file would be helpful too.
I actually plan to use "version" instead of "timestamp".
It's easy enough to add the timestamp tag manually, but it will be wiped
out sny time we update the schema and re-run Middlegen! So we need to
be able to add this via Middlegen config somehow.
Thanks!
Vick
|
| |
| Re: Middlegen version setup
| 18 Oct 2005, 14:51
| fisherv
|
Here is one way to get Middlegen to generate the <version> tag content
in the xxx.hbm.xml files.
In the Middlegen GUI, the only choice for "column specialty" is
"property", but we need another choice: "version". To get around this,
edit the model-prefs.properties file for your application. Find the line
for your version attribute that says something like:
hibernate.tables.CLAIM.columns.VERSION.columnspecialty=property
and change it to:
hibernate.tables.CLAIM.columns.VERSION.columnspecialty=version
This is what would happen if you chose "version" from the drop down in
the Middlegen GUI. Then re-run Middlegen as usual to get the desired
<version> section in your xxx.hbm.xml file(s).
|
| |
| Re: Middlegen timestamp/version setup? (attn: David)
| 27 Apr 2006, 07:37
| abnerp
|
>------------------------------------------------------------
>David, how did you get middlegen to create the timestamp tag?
><timestamp name="departureUtc" column="departure_utc" />
>Add this in your node column in your preference file :
><entry key="columnspecialty" value="version" />
>------------------------------------------------------------
Hi, I still want to know how can I create the "timestamp" tag with
middlegen.
The prefs file is not a good solution, because sometimes we have to
delete the file so that middlegen can create the file again.
>Could someone let me know to which "preference file" we should add the
><entry.../> line mentioned above?
>It's easy enough to add the timestamp tag manually, but it will be
>wiped
>out sny time we update the schema and re-run Middlegen! So we need to
>be able to add this via Middlegen config somehow.
I wanna know a way to specify this by build.xml or some ANT or VM parameter.
Someone can tell where we use the "entry" tag? Seens to be a good
solution, but I'm afraid that can't be used with Hibernate Plugin. Is
that correct?
Someone can help me?
Thanks,
Abner
|
| |
| Typo Error
| 27 Dec 2006, 14:27
| rathin
|
Please fix the scrambled text in the code sample followed by - The
internal generation of composite keys can be selected as below.
|
| |
| From .java to .hbm
| 29 Jan 2007, 12:44
| neuquino
|
I know that there is a way to get .hbm files from .java files. Using the
class xdoclet.modules.hibernate.HibernateDocletTask. Can't middlegen do
that? I know this class is from xdoclet, but I would like to use only
one tool for everything...
|
| |
| Re: From .java to .hbm
| 05 Feb 2007, 05:50
| emmie
|
POST QUESTIONS ON THE FORUM! COMMENTS HERE SHOULD ADD VALUE TO THE
PAGE!On 29 Jan 2007 12:44, neuquino wrote:
>I know that there is a way to get .hbm files from .java files. Using
the
>class xdoclet.modules.hibernate.HibernateDocletTask. Can't middlegen
do
>that? I know this class is from xdoclet, but I would like to use only
>one tool for everything...
There are two approaches to software engineering: top down and
button up.
XDoclet focuses on the top down approach: from .java files it
generates .hbm.xml mapping files and from these, it is posible to
generate database using hbm2ddl tool.
Middlegen focuses on the button up approach: from database it
generates .hbm.xml mappins files, and from these, it is posible to
generate .java files using hbm2java tool (only for hibernate 2.x).
Conclusion: these tools (XDoclet and Middlegen) have diferente
porpuses. Therefore, you can choose one depending on what you
want to do.
PS: I'm "neuquino" too, I give you my email address in order to keep in
touch: emiliano.pereyra (at) hotmail (dot) com
|
| |
| middlegen.MiddlegenException: Couldn't connect to database
| 02 Oct 2007, 09:24
| smaskar
|
POST QUESTIONS ON THE FORUM! COMMENTS HERE SHOULD ADD VALUE TO THE
PAGE!I have MSSQLSERVER Express on windows Vista I can setup the database
using the Ant task but when I try to execute the middlegen ant task it
gives me an error saying
Before getting the following error there was Ant debug statement
- Class com.inet.tds.h loaded from ant loader (parentFirst)
Class java.lang.Math loaded from parent loader (parentFirst)
Class java.lang.OutOfMemoryError loaded from parent loader (parentFirst)
is the above line causes to load the driver?
\build.xml:453: middlegen.MiddlegenException: Couldn't connect to
database: [TDS Driver]Connection was closed from the SQL Serv
er site or network at header (0)
at middlegen.MiddlegenTask.execute(MiddlegenTask.java:477)
at
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
-Santosh
|
| |
| Re: middlegen.MiddlegenException: Couldn't connect to database
| 04 Oct 2007, 08:08
| smaskar
|
POST QUESTIONS ON THE FORUM! COMMENTS HERE SHOULD ADD VALUE TO THE
PAGE!I got this working. The problem was windows Vista firewall setting.
-Santosh
|
| |
| Using Middlegen on iSeries/AS400
| 07 May 2008, 06:35
| ratnesh_22
|
I have shared my experience here.
http://rmwebcafe.blogspot.com/
|
| |
| Re: would you like to help me?
| 30 Jul 2008, 07:23
| manjun
|
POST QUESTIONS ON THE FORUM! COMMENTS HERE SHOULD ADD VALUE TO THE PAGE!
On 10 Nov 2003 04:17, hudh wrote:
>hi,
> I set up the middlegen-hibernate-r2 and configure the buid.xml and
>oracle.xml and then execute the ant command,but exception out is there
>is no tables .but i am sure there is lots of tables with my oracle.xml
>configuration.
> Doesn't It support oracle generation?
set the schema="" attribute and try.
|
| |
|