Discussion:
[Middlegen-user] Re: middlegen-user digest, Vol 1 #653 - 1 msg
Chintan
2004-08-12 02:49:08 UTC
Permalink
Yes, I did this for Oracle. See the, sql2java.java
file.

best,
Chintan
Send middlegen-user mailing list submissions to
To subscribe or unsubscribe via the World Wide Web,
visit
https://lists.sourceforge.net/lists/listinfo/middlegen-user
or, via email, send a message with subject or body
'help' to
You can reach the person managing the list at
When replying, please edit your Subject line so it
is more specific
than "Re: Contents of middlegen-user digest..."
1. mapping DB types to Java types (Jonathan
Scott)
--__--__--
Message: 1
Date: Thu, 12 Aug 2004 10:25:20 +0900
Organization: Vanten
Subject: [Middlegen-user] mapping DB types to Java
types
Hi All,
Looking through the MiddleGen site, I am worried it
is not at all possible to force certain DB types to
specific Java classes.
PostgreSQL has a type "inet" which is an IP address.
MiddleGen does not understand this type and thus
marks it as "Object" in our hbm.xml files. We would
like to map it to another class.
Is there any configuration file/option etc. that I
could use to achieve this? Any pointers would be
more than welcome.
TIA,
Jonathan Scott
--__--__--
_______________________________________________
middlegen-user mailing list
https://lists.sourceforge.net/lists/listinfo/middlegen-user
End of middlegen-user Digest
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail
Jonathan Scott
2004-08-12 05:35:02 UTC
Permalink
Thank you for the reply.

I am overloading the HibernateJavaTypeMapper method getPreferredJavaType(), as mentioned in 98.html on the hibernate site. Problem is, even after changing the build.xml to point to my new javaTypeMapper class, it still does not get called. I have tried putting in println() statements and specifying bogus java classes, yet everything compiles fine.

Has anyone done this before? And if possible, could you provide a reference?

Jonathan Scott


On Wed, 11 Aug 2004 21:48:30 -0700 (PDT)
Post by Chintan
Yes, I did this for Oracle. See the, sql2java.java
file.
best,
Chintan
Send middlegen-user mailing list submissions to
To subscribe or unsubscribe via the World Wide Web,
visit
https://lists.sourceforge.net/lists/listinfo/middlegen-user
or, via email, send a message with subject or body
'help' to
You can reach the person managing the list at
When replying, please edit your Subject line so it
is more specific
than "Re: Contents of middlegen-user digest..."
1. mapping DB types to Java types (Jonathan
Scott)
--__--__--
Message: 1
Date: Thu, 12 Aug 2004 10:25:20 +0900
Organization: Vanten
Subject: [Middlegen-user] mapping DB types to Java
types
Hi All,
Looking through the MiddleGen site, I am worried it
is not at all possible to force certain DB types to
specific Java classes.
PostgreSQL has a type "inet" which is an IP address.
MiddleGen does not understand this type and thus
marks it as "Object" in our hbm.xml files. We would
like to map it to another class.
Is there any configuration file/option etc. that I
could use to achieve this? Any pointers would be
more than welcome.
TIA,
Jonathan Scott
--__--__--
_______________________________________________
middlegen-user mailing list
https://lists.sourceforge.net/lists/listinfo/middlegen-user
End of middlegen-user Digest
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail
-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285
_______________________________________________
middlegen-user mailing list
https://lists.sourceforge.net/lists/listinfo/middlegen-user
Gill, Cory (FIN)
2004-08-12 10:46:06 UTC
Permalink
Hi Jonathan,

I ran into this problem on a recent project as well. We generated our EJBs
through WebSphere Application Developer's bottom up mapping utility and used
Middlegen to generate our business objects and struts classes.

The problem was that the type conversion algorithm WSAD used to create EJBs
from database tables was different than that used by the Middlegen Java
plugin. In particular WSAD makes all CMP fields in an entity bean objects
whereas the Java plugin for Middlegen will create fields with primitive
types.

To work around this problem I would first start Middlegen with the GUI
enabled and then shut it down. This would load the preferences file update
it, if necessary, and then save it to disk. (prefsdir="./prefs" in
middlegen ant task)

Once Middlegen had been shut down I would open up the prefs file and do a
search and replace on:

search : java-type=int
replace : java-type=Integer

I'm hoping to get some time in the upcoming weeks to make an extension to
the Java plugin to allow for a prettier solution.

Good Luck

Cory Gill

-----Original Message-----
From: Jonathan Scott [mailto:***@vanten.com]
Sent: Wednesday, August 11, 2004 9:25 PM
To: middlegen-***@lists.sourceforge.net
Subject: [Middlegen-user] mapping DB types to Java types


Hi All,

Looking through the MiddleGen site, I am worried it is not at all possible
to force certain DB types to specific Java classes.

PostgreSQL has a type "inet" which is an IP address. MiddleGen does not
understand this type and thus marks it as "Object" in our hbm.xml files. We
would like to map it to another class.

Is there any configuration file/option etc. that I could use to achieve
this? Any pointers would be more than welcome.

TIA,
Jonathan Scott


-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285
Gill, Cory (FIN)
2004-08-12 15:47:03 UTC
Permalink
Hi Darren,

Thanks for the information. I just opened up my own custom plugin (extends
Java Plugin) and added the following lines in the init() method:

Sql2Java.overridePreferredJavaTypeForSqlType(Types.INTEGER,
"Integer");

Sql2Java.overridePreferredJavaTypeForSqlType(Types.TIMESTAMP,
"java.sql.Timestamp");
Sql2Java.overridePreferredJavaTypeForSqlType(Types.DATE,
"java.sql.Date");
Sql2Java.overridePreferredJavaTypeForSqlType(Types.DECIMAL,
"java.math.BigDecimal");
Sql2Java.overridePreferredJavaTypeForSqlType(Types.NUMERIC,
"java.math.BigDecimal");
Sql2Java.overridePreferredJavaTypeForSqlType(Types.CHAR,
"String");
Sql2Java.overridePreferredJavaTypeForSqlType(Types.SMALLINT,
"Integer");

Works like a charm... and no modifying of the preferences file required!

Thanks,

Cory

-----Original Message-----
From: Darren Hartford [mailto:***@ghsinc.com]
Sent: Thursday, August 12, 2004 9:28 AM
To: middlegen-***@lists.sourceforge.net
Subject: AW: [Middlegen-user] mapping DB types to Java types


I, as well as probably a lot of other people, ended up hard-coding the
Sql2Java source code in Middlegen for what you need and recompile. As an
example, this is what I have at the bottom of the Sql2Java.java file:

static {
_preferredJavaTypeForSqlType.put(Types.TINYINT, "java.lang.Integer");
_preferredJavaTypeForSqlType.put(Types.SMALLINT, "java.lang.Integer");
_preferredJavaTypeForSqlType.put(Types.INTEGER, "java.lang.Integer");
_preferredJavaTypeForSqlType.put(Types.BIGINT, "java.lang.Integer");
_preferredJavaTypeForSqlType.put(Types.REAL, "java.lang.Float");
_preferredJavaTypeForSqlType.put(Types.FLOAT, "java.lang.Float");
_preferredJavaTypeForSqlType.put(Types.DOUBLE, "java.lang.Float");
_preferredJavaTypeForSqlType.put(Types.DECIMAL,
"java.math.BigDecimal");
_preferredJavaTypeForSqlType.put(Types.NUMERIC,
"java.math.BigDecimal");
_preferredJavaTypeForSqlType.put(Types.BIT, "java.lang.Boolean");
_preferredJavaTypeForSqlType.put(Types.CHAR, "java.lang.String");
_preferredJavaTypeForSqlType.put(Types.VARCHAR, "java.lang.String");
// according to resultset.gif, we should use java.io.Reader, but
String is more convenient for EJB
_preferredJavaTypeForSqlType.put(Types.LONGVARCHAR,
"java.lang.String");
_preferredJavaTypeForSqlType.put(Types.BINARY, "byte[]");
_preferredJavaTypeForSqlType.put(Types.VARBINARY, "byte[]");
_preferredJavaTypeForSqlType.put(Types.LONGVARBINARY, "byte[]");
_preferredJavaTypeForSqlType.put(Types.DATE, "java.util.Date");
_preferredJavaTypeForSqlType.put(Types.TIME, "java.util.Date");
_preferredJavaTypeForSqlType.put(Types.TIMESTAMP, "java.util.Date");
_preferredJavaTypeForSqlType.put(Types.CLOB, "byte[]");
_preferredJavaTypeForSqlType.put(Types.BLOB, "byte[]");
_preferredJavaTypeForSqlType.put(Types.ARRAY, "java.sql.Array");
_preferredJavaTypeForSqlType.put(Types.REF, "java.sql.Ref");
_preferredJavaTypeForSqlType.put(Types.STRUCT, "java.lang.Object");
_preferredJavaTypeForSqlType.put(Types.JAVA_OBJECT,
"java.lang.Object");
}

Opposed to the above solution, if you are using *only* Hibernate, I would
recommend getting the most recent (R5 I think) of the Hibernate-Middlegen
plugin from Hibernate's site and write a class to implement JavaTypeMapper
and override the "public String getPreferredJavaType(JavaColumn column)"
method to have it return what you want it to. Then, if using Ant, add a
property to the Middlegen/Hibernate subtask for 'javaTypeMapper=' and point
it to this class (making sure the class is in the classpath).

Hope this helps you get started, in between things at the momement so this
is a quick response.

-D
Post by Gill, Cory (FIN)
-----Original Message-----
Sent: Wednesday, August 11, 2004 9:25 PM
Subject: [Middlegen-user] mapping DB types to Java types
Hi All,
Looking through the MiddleGen site, I am worried it is not at
all possible
to force certain DB types to specific Java classes.
PostgreSQL has a type "inet" which is an IP address.
MiddleGen does not
understand this type and thus marks it as "Object" in our
hbm.xml files. We
would like to map it to another class.
Is there any configuration file/option etc. that I could use
to achieve
this? Any pointers would be more than welcome.
TIA,
Jonathan Scott
-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285

Loading...