- This topic has 3 replies, 2 voices, and was last updated 19 years, 1 month ago by Riyad Kalla.
-
AuthorPosts
-
tarantulaParticipantHi,
I’m trying to implement a Boolean property in one of my model objects using MyEclipse 4.0M3, Eclipse 3.1, Hibernate 3.0, MySQL 4.1 and MySQL Connector/J 3.1.10. My database table uses a tinyint(1) field type but the generated Java code maps to a java.lang.Byte.
Previous versions of MyEclipse/Hibernate would generate a java.lang.Short Java property to map to the tinyint(1) MySQL type. The MySQL 4.1 documentation says that tinyint(1) should map to:
java.lang.Boolean if the configuration property “tinyInt1isBit” is set to “true” (the default) and the storage size is “1”, or java.lang.Integer if not.
If this is so, why is the Hibernate tooling mapping it to a java.lang.Byte? Can you give me some advice on how to properly implement Boolean properties with MyEclipse? I would also accept some advice on how to work with Bytes as Booleans in Java (if this is possible).
Many thanks,
tarantula
Riyad KallaMembertarantula,
We have had the bug of the mapper being a bit overzealous with mapping things to Byte when it’s not sure for a while now and honestly the “fix” was going to be rolling out the VIsual Hibernate mapper, but at the last minute as you know it didn’t make the 4.0 cute. Unfortunately I don’t have an automated workaround for you right now, while it is a pain in this case we coded the mapper to generate “safe” mappings, meaning the Byte mappings will work in all cases where if we always mapped tinyint(1) fields to Boolean I can imagine a few complaints popping up fairly quickly.As far as how to work with Byte values instead, assuming your app is using 1 and 0 for true/false you could find the byte value for 1 and 0, or just print out the value and see what it comes out to.
tarantulaParticipant@support-rkalla wrote:
tarantula,
We have had the bug of the mapper being a bit overzealous with mapping things to Byte when it’s not sure for a while now and honestly the “fix” was going to be rolling out the VIsual Hibernate mapper, but at the last minute as you know it didn’t make the 4.0 cute. Unfortunately I don’t have an automated workaround for you right now, while it is a pain in this case we coded the mapper to generate “safe” mappings, meaning the Byte mappings will work in all cases where if we always mapped tinyint(1) fields to Boolean I can imagine a few complaints popping up fairly quickly.As far as how to work with Byte values instead, assuming your app is using 1 and 0 for true/false you could find the byte value for 1 and 0, or just print out the value and see what it comes out to.
Thanks for your reply rkalla. I have tried using Byte in my Java apps to accommodate your TINYINT(1) to Byte Hibernate mapping but this approach has become cumbersome and I’m sure I’m not the only one who is feeling pain over this.
What is needed is more fine-grained control of the Hibernate reverse engineering process. I know you guys are planning to migrate to Hibernate Tools at some point, and that we need to run a separate Eclipse installation for that purpose (see link below), but that leaves me stranded because I don’t want to split my projects in two and have one IDE for Hibernate and another for Spring/JSF/etc.
http://www.myeclipseide.com/PNphpBB2+file-viewtopic-t-9623.html
What should I do?
Riyad KallaMemberIf you can hang in there a little longer, 4.1 will include our first pass of integrating the Hibernate Tools work, which will be the mapper. We still have plans to integrate more and enhance it further, but this first step should get you closer to what you need.
In the interm there is the Hibernate Synchronizer project that is quite popular and lives quite happily along side MyEclipse, but eventually we will pull in all the powerful features of Hibernate Tools (Starting in 4.1 and going through 5.0), because we realize that our Hibernate users have been floundering for a while with some weak mapping generation and appologize for that.
-
AuthorPosts