请教关于用middlegen生成部分库表的映射文件的问题?(150分)

  • 主题发起人 主题发起人 大唐电信
  • 开始时间 开始时间

大唐电信

Unregistered / Unconfirmed
GUEST, unregistred user!
我在生成映射文件时,如果把库里的表全都映射,就没问题。
但如果我只想映射部分表,
比如我在配置文件里加一句:
<table generate=&quot;true&quot;
name=&quot;OCABLE&quot;
pktable=&quot;PK_OCABLE&quot;/>
在ant的时候就会抱错,
D:/CG/Middlegen-Hibernate-r5/build.xml:148: java.lang.OutOfMemoryError
请问各位大虾这是什么原因,应该如何解决?
 
配置文件如下:
<?xml version=&quot;1.0&quot;?>
<!--
This is a testing platform for the middlegen hibernate plugin. It is a stripped
down version of the samples application. At the moment it is only concerned
with the generation of the mappingdo
cuments so that various tests etc can be
done on the generated package.
David Channon

Thedo
CTYPE declaration declares the location of product-specific parts of the
Ant build file. You can change the values of these declarations to point to
other available files. This gives you an opportunity to choose what database.
Note that this syntax has nothing todo
with Ant or Middlegen. This
is the standard way defined by w3c to dynamically include external
files in an XMLdo
cument. Any decent XML parser willdo
the include
transparently. Try to open this file in Internet Explorer and see
for yourself.
-->
<!DOCTYPE project [
<!ENTITY database SYSTEM &quot;file:./config/database/oracle.xml&quot;>
]>

<project name=&quot;Middlegen Hibernate&quot;
default=&quot;all&quot;
basedir=&quot;.&quot;>
<!-- project name=&quot;Middlegen Hibernate&quot;
default=&quot;all&quot;
basedir=&quot;.&quot;
-->

<property file=&quot;${basedir}/build.properties&quot;/>
<property name=&quot;name&quot;
value=&quot;RMS&quot;/>
<!-- This was added because we were several people (in a course) deploying to same app server>
<property environment=&quot;env&quot;/>
<property name=&quot;unique.name&quot;
value=&quot;${name}.${env.COMPUTERNAME}&quot;/-->
<property name=&quot;gui&quot;
value=&quot;true&quot;/>
<property name=&quot;unique.name&quot;
value=&quot;${name}&quot;/>
<property name=&quot;appxml.src.file&quot;
value=&quot;${basedir}/src/application.xml&quot;/>
<property name=&quot;lib.dir&quot;
value=&quot;${basedir}/lib&quot;/>
<property name=&quot;src.dir&quot;
value=&quot;${basedir}/src&quot;/>
<property name=&quot;java.src.dir&quot;
value=&quot;${src.dir}/java&quot;/>
<property name=&quot;web.src.dir&quot;
value=&quot;${src.dir}/web&quot;/>

<property name=&quot;build.dir&quot;
value=&quot;${basedir}/build&quot;/>
<property name=&quot;build.java.dir&quot;
value=&quot;${build.dir}/java&quot;/>
<property name=&quot;build.gen-src.dir&quot;
value=&quot;D:/temp&quot;/>
<property name=&quot;build.classes.dir&quot;
value=&quot;${build.dir}/classes&quot;/>
&database;

<!-- define the datasource.jndi.name in case the imported ejb filedo
esn't -->
<property name=&quot;datasource.jndi.name&quot;
value=&quot;${name}/datasource&quot;/>
<path id=&quot;lib.class.path&quot;>
<pathelement path=&quot;${database.driver.classpath}&quot;/>
<fileset dir=&quot;${lib.dir}&quot;>
<include name=&quot;*.jar&quot;/>
</fileset>
<!-- The middlegen jars -->
<!--fileset dir=&quot;${basedir}/..&quot;-->
<fileset dir=&quot;${basedir}/middlegen-lib&quot;>
<include name=&quot;*.jar&quot;/>
</fileset>
</path>
<target name=&quot;init&quot;>
<available property=&quot;xdoclet1.2+&quot;
classname=&quot;xdoclet.modules.hibernate.HibernateDocletTask&quot;
classpathref=&quot;lib.class.path&quot;/>
</target>
<!-- =================================================================== -->
<!-- Fails if XDoclet 1.2.x is not on classpath -->
<!-- =================================================================== -->
<target name=&quot;fail-if-no-xdoclet-1.2&quot;
unless=&quot;xdoclet1.2+&quot;>
<fail>
You mustdo
wnload several jar files before you can build Middlegen.
</fail>
</target>
<!-- =================================================================== -->
<!-- Create tables -->
<!-- =================================================================== -->
<target
name=&quot;create-tables&quot;
depends=&quot;init,fail-if-no-xdoclet-1.2,check-driver-present,panic-if-driver-not-present&quot;
description=&quot;Create tables&quot;
>
<echo>Creating tables using URL ${database.url}</echo>
<sql
classpath=&quot;${database.driver.classpath}&quot;
driver=&quot;${database.driver}&quot;
url=&quot;${database.url}&quot;
userid=&quot;${database.userid}&quot;
password=&quot;${database.password}&quot;
src=&quot;${database.script.file}&quot;
print=&quot;true&quot;
output=&quot;result.txt&quot;
/>
</target>
<target name=&quot;check-driver-present&quot;>
<available file=&quot;${database.driver.file}&quot;
type=&quot;file&quot;
property=&quot;driver.present&quot;/>
</target>
<target name=&quot;panic-if-driver-not-present&quot;
unless=&quot;driver.present&quot;>
<fail>
The JDBC driver you have specified by including one of the files in ${basedir}/config/database
do
esn't exist. You have todo
wnload this driver separately and put it in ${database.driver.file}
Please make sure you're using a version that is equal or superior to the one we looked for.
If you name the driver jar file differently, please update the database.driver.file property
in the ${basedir}/config/database/xxx.xml file accordingly.
</fail>
</target>
<!-- =================================================================== -->
<!-- Run Middlegen -->
<!-- =================================================================== -->
<target
name=&quot;middlegen&quot;
description=&quot;Run Middlegen&quot;
unless=&quot;middlegen.skip&quot;
depends=&quot;init,fail-if-no-xdoclet-1.2,check-driver-present,panic-if-driver-not-present&quot;
>
<mkdir dir=&quot;${build.gen-src.dir}&quot;/>
<echo message=&quot;Class path = ${basedir}&quot;/>
<taskdef
name=&quot;middlegen&quot;
classname=&quot;middlegen.MiddlegenTask&quot;
classpathref=&quot;lib.class.path&quot;
/>
<middlegen
appname=&quot;${name}&quot;
prefsdir=&quot;${src.dir}&quot;
gui=&quot;${gui}&quot;
databaseurl=&quot;${database.url}&quot;
initialContextFactory=&quot;${java.naming.factory.initial}&quot;
providerURL=&quot;${java.naming.provider.url}&quot;
datasourceJNDIName=&quot;${datasource.jndi.name}&quot;
driver=&quot;${database.driver}&quot;
username=&quot;${database.userid}&quot;
password=&quot;${database.password}&quot;
schema=&quot;${database.schema}&quot;
catalog=&quot;${database.catalog}&quot;
>
<!--
We can specify what tables we want Data generated for.
If none are specified, Data 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.
-->
<!--table generate=&quot;true&quot;
name=&quot;flights&quot;
pktable=&quot;flights_pk&quot;/-->
<table generate=&quot;false&quot;
name=&quot;OCABLE&quot;
pktable=&quot;PK_OCABLE&quot;/>
<!--table generate=&quot;true&quot;
name=&quot;OPAIRCONN&quot;
pktable=&quot;PK_OPAIRCONN&quot;/-->
<!--
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=&quot;true&quot;
name=&quot;persons&quot;/>
<jointable name=&quot;reservations&quot;
generate=&quot;false&quot;/>
<tableb generate=&quot;true&quot;
name=&quot;flights&quot;/>
</many2many-->

<!-- Plugins - Only Hibernate Plugin has been included with this special distribution -->

<!--
If you want to generate XDoclet markup for hbm2java to include in the POJOs then
set genXDocletTags to true. Also, composite keys are generated as external classes which is
recommended. If you wish to keep them internal then
set genIntergratedCompositeKeys to true.
Since r4 the ability to customise the selection of JavaTypes is now provided. The is a
recommended type mapper provided as shown. It is optional - if not provided then
Middlegen
itself will select the Java mapping (as it did previously).
These settings are optional thus if they are not define here values default to false.
-->
<hibernate
destination=&quot;${build.gen-src.dir}&quot;
package=&quot;cgpackage&quot;
genXDocletTags=&quot;true&quot;
genIntergratedCompositeKeys=&quot;false&quot;
javaTypeMapper=&quot;middlegen.plugins.hibernate.HibernateJavaTypeMapper&quot;
/>

</middlegen>
<mkdir dir=&quot;${build.classes.dir}&quot;/>
</target>
<!-- =================================================================== -->
<!-- Compile business logic (hibernate) -->
<!-- =================================================================== -->
<target name=&quot;compile-hibernate&quot;
depends=&quot;middlegen&quot;
description=&quot;Compile hibernate Businessdo
main Model&quot;>
<javac
srcdir=&quot;${build.gen-src.dir}&quot;
destdir=&quot;${build.classes.dir}&quot;
classpathref=&quot;lib.class.path&quot;
>
<include name=&quot;**/hibernate/**/*&quot;/>
</javac>
</target>

<!-- =================================================================== -->
<!-- Run hbm2java depends=&quot;middlegen&quot;
-->
<!-- =================================================================== -->
<target name=&quot;hbm2java&quot;
description=&quot;Generate .java from .hbm files.&quot;>
<taskdef
name=&quot;hbm2java&quot;
classname=&quot;net.sf.hibernate.tool.hbm2java.Hbm2JavaTask&quot;
classpathref=&quot;lib.class.path&quot;
/>

<hbm2java output=&quot;${build.gen-src.dir}&quot;>
<fileset dir=&quot;${build.gen-src.dir}&quot;>
<include name=&quot;**/*.hbm.xml&quot;/>
</fileset>
</hbm2java>
</target>
<!-- =================================================================== -->
<!-- Build everything -->
<!-- =================================================================== -->
<target name=&quot;all&quot;
description=&quot;Build everything&quot;
depends=&quot;compile-hibernate&quot;/>
<!-- =================================================================== -->
<!-- Clean everything -->
<!-- =================================================================== -->
<target name=&quot;clean&quot;
description=&quot;Clean all generated stuff&quot;>
<delete dir=&quot;${build.dir}&quot;/>
</target>
<!-- =================================================================== -->
<!-- Brings up the hsqldb admin tool -->
<!-- =================================================================== -->
<target name=&quot;hsqldb-gui&quot;
description=&quot;Brings up the hsqldb admin tool&quot;>
<property name=&quot;database.urlparams&quot;
value=&quot;?user=${database.userid}&amp;password=${database.password}&quot;/>
<java
classname=&quot;org.hsqldb.util.DatabaseManager&quot;
fork=&quot;yes&quot;
classpath=&quot;${lib.dir}/hsqldb-1.7.1.jar;${database.driver.classpath}&quot;
failonerror=&quot;true&quot;
>
<arg value=&quot;-url&quot;/>
<arg value=&quot;${database.url}${database.urlparams}&quot;/>
<arg value=&quot;-driver&quot;/>
<arg value=&quot;${database.driver}&quot;/>
</java>
</target>
<!-- ==================================================================== -->
<!-- Validate the generated xml mappingdo
cuments -->
<!-- ==================================================================== -->
<target name=&quot;validate&quot;>
<xmlvalidate failonerror=&quot;no&quot;
lenient=&quot;no&quot;
warn=&quot;yes&quot;>
<fileset dir=&quot;${build.gen-src.dir}/airline/hibernate&quot;
includes=&quot;*.xml&quot;
/>
</xmlvalidate>
</target>

</project>
 
这个工具不好用,有很多类似的工具可以选用。
 
我用myeclipse可以生成映射文件
顺便问一下:先有PO,还是先有表?
 
这个问题已经解决了,只要重起一下操作系统就行了,不知道为什么。但现在改成用middlegenide这个,更方便。
一般都是先有表,然后生成映射文件,根据映射文件在生成POJO.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
I
回复
0
查看
609
import
I
后退
顶部