• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Rob Spoor
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:

Problem with Mapping between 1 bit column and boolean field

 
Sheriff
Posts: 9704
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I am having a problem with entity beans in EJB 3.0. I am using jBoss 4.0.4 application server with MySQL 5.0.


I have a field in the database whose size is 1 bit. It is mapped to a boolean field in the class. Now I think that when the value in the database is 1, then the boolean field must be set to true. But this is not happening. The boolean field's value is evaluating to false. I don't what is the reason behind this. Can anyone help me with this :roll:

Thanks in advance
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are using MySQL5, create the column in the database as a BOOLEAN type instead of BIT type. See if that works.
 
Ankit Garg
Sheriff
Posts: 9704
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Working like a charm now. Thanks again Jaikiran

But this is a very big project and it is working on the system of everyone on the team. I don't know whether they will let me change the column type or not :roll:
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Garg wrote:

But this is a very big project and it is working on the system of everyone on the team. I don't know whether they will let me change the column type or not



You have one other option which you could try out. I'm not sure whether its going to work, though. But since you are using MySQL 5.x, you definitely should be using MySQL5Dialect with Hibernate. Have you configured your hibernate configuration file (or if you are using JPA, then persistence.xml) to use org.hibernate.dialect.MySQL5Dialect
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Ankit

There is another work around given that you do not have the authority to change the DDL.

Simply mapped the BIT column to the corresponding types in Java. Then create an accessor method that simply return boolean with respect to the instance variable that maps to the BIT column. You do not need to have getters/setters for the instance variable mapped to the BIT column in order not to confuse the callers of the class.

@Jaikiran

I do not think EJB 3.0 supports that kind of functionality. That is proprietary to Hibernate in itself. If you simply use the Hibernate as a persistence provider, then it will be constrained
to the rules and specs of EJB 3.0.

Regards.
 
Ankit Garg
Sheriff
Posts: 9704
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well this is my persistence.xml file



I think jaikiran you are talking about the provider value i.e. I need to write org.hibernate.dialect.MySQL5Dialect instead of org.hibernate.ejb.HibernatePersistence am I right?? Also Jerwin I can't change the class implementation either. They will not allow me to do that
 
Jerwin Louise Uy
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you do not have access to the entity beans, then it is a leakage of concerns, i.e. the concern of the domain model objects proliferated the concern of the client code.

Really, it is just a matter of "them"(the one in charge of the creating the domain model objects) testing the finder methods whether the mapping of the BIT column really reflected the expected Boolean counterpart.

I suggest that you inform the people in charge of the entity beans because if you can't change the domain model, then there is no way to get the right value unless you create another entity bean mapped to the same table.

Regards.

 
Ankit Garg
Sheriff
Posts: 9704
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jerwin this is really a matter of what THEY want. I can't help it. But since no one was able to solve my problem, so THEY allowed me to have a local copy of the database to work on. So now I don't have to worry about this anymore
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jerwin Louise Uy wrote:
@Jaikiran

I do not think EJB 3.0 supports that kind of functionality. That is proprietary to Hibernate in itself. If you simply use the Hibernate as a persistence provider, then it will be constrained
to the rules and specs of EJB 3.0.



Jerwin,

The persistence.xml is allowed to configure provider specific properties through the "properties" element. Here's an example:



However, i do agree that these properties are Hibernate specific and will be of no use when some other JPA implementation is used.

Jerwin Louise Uy wrote:
If you do not have access to the entity beans, then it is a leakage of concerns, i.e. the concern of the domain model objects proliferated the concern of the client code.

Really, it is just a matter of "them"(the one in charge of the creating the domain model objects) testing the finder methods whether the mapping of the BIT column really reflected the expected Boolean counterpart.



+1


 
I am going to test your electrical conductivity with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic