-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Mapping specific characters to boolean values
PostPosted: Sun Oct 03, 2004 8:56 am 
Beginner
Beginner

Joined: Sun Oct 03, 2004 8:50 am
Posts: 32
Location: McLean, VA
I'm working on a project with an existing database. There are a number of columns that represent boolean values (wether the record is active or not). Instead of using 1/0 or T/F as most DBs I've seen this client uses A/I (active/inactive). How can I get Hibernate to map A to true and I to false?

[b]Hibernate version:[/b]
2.1.6

[b]Name and version of the database you are using:[/b]
Oracle 9i

[b]Full stack trace of any exception that occurs:[/b]
Caused by: java.lang.NumberFormatException: For input string: "A"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1207)
at java.lang.Double.valueOf(Double.java:202)
at oracle.jdbc.driver.OracleStatement.getBooleanValue(OracleStatement.java:4409)
at oracle.jdbc.driver.OracleResultSetImpl.getBoolean(OracleResultSetImpl.java:479)
at oracle.jdbc.driver.OracleResultSet.getBoolean(OracleResultSet.java:1494)
at weblogic.jdbc.wrapper.ResultSet_oracle_jdbc_driver_OracleResultSetImpl.getBoolean(Unknown Source)
at net.sf.hibernate.type.BooleanType.get(BooleanType.java:19)
at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:62)
at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:53)
at net.sf.hibernate.type.AbstractType.hydrate(AbstractType.java:66)
at net.sf.hibernate.loader.Loader.hydrate(Loader.java:686)
at net.sf.hibernate.loader.Loader.loadFromResultSet(Loader.java:627)
at net.sf.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:586)
at net.sf.hibernate.loader.Loader.getRow(Loader.java:501)
at net.sf.hibernate.loader.Loader.getRowFromResultSet(Loader.java:213)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:281)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1544)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at gov.epa.icis.common.server.dao.hibernate.HibernateTemplate.getVOs(HibernateTemplate.java:258)
at gov.epa.icis.dao.sysadmin.StateDAO.getStates(StateDAO.java:63)
at gov.epa.icis.sysadmin.server.ejb.SystemAdminSB.getStates(SystemAdminSB.java:84)
at gov.epa.icis.sysadmin.server.ejb.SystemAdmin_qbf5pt_EOImpl.getStates(SystemAdmin_qbf5pt_EOImpl.java:262)
at gov.epa.icis.sysadmin.server.ejb.SystemAdmin_qbf5pt_EOImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.ServerRequest.sendReceive(ServerRequest.java:166)

_________________
- Chad


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 03, 2004 9:25 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Use a custom UserType


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 03, 2004 9:52 am 
Beginner
Beginner

Joined: Sun Oct 03, 2004 8:50 am
Posts: 32
Location: McLean, VA
Thanks for the direction. I found the CharBooleanType and extended it (don't know why I missed it the last time I looked at the UserType stuff). Now is there any way to tell hibernate to use my new type for all our boolean columns or do I need to specify this custom type for each property indvidually?

_________________
- Chad


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 03, 2004 10:22 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You need to specify it for each individually


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 03, 2004 10:34 am 
Beginner
Beginner

Joined: Sun Oct 03, 2004 8:50 am
Posts: 32
Location: McLean, VA
Okay. Like I said, I extended the CharBooleanType class and created a type called ActiveInactiveType. I mapped it to my POJO's property as follows:

Code:
   /**
    * @hibernate.property column="STATUS_FLAG"
    *  type="gov.epa.icis.common.server.dao.hibernate.ActiveInactiveType"
    */
    public boolean isActive()
    {
        return active;
    }


However, now I get the following exception (I've verified I don't have any typos in the type mapping). Any suggestions what might cause this?

Code:
net.sf.hibernate.MappingException: Could not interpret type: gov.epa.icis.common.server.dao.hibernate.ActiveInactiveType
        at net.sf.hibernate.cfg.Binder.getTypeFromXML(Binder.java:934)
        at net.sf.hibernate.cfg.Binder.bindSimpleValue(Binder.java:435)
        at net.sf.hibernate.cfg.Binder.propertiesFromXML(Binder.java:1047)
        at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:362)
        at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1256)
        at net.sf.hibernate.cfg.Configuration.add(Configuration.java:252)
        at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:288)
        at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:336)
        at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:1013)
        at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:969)
        at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:897)
        at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:883)
        at gov.epa.icis.common.server.dao.hibernate.HibernateTemplate.<init>(HibernateTemplate.java:64)
        at gov.epa.icis.common.server.dao.hibernate.HibernateTemplate.getInstance(HibernateTemplate.java:98)
        at gov.epa.icis.common.server.dao.hibernate.HibernateTemplate.getInstance(HibernateTemplate.java:83)
        at gov.epa.icis.dao.sysadmin.StateDAO.<init>(StateDAO.java:33)
        at gov.epa.icis.sysadmin.server.ejb.SystemAdminSB.getStates(SystemAdminSB.java:83)
        at gov.epa.icis.sysadmin.server.ejb.SystemAdmin_qbf5pt_EOImpl.getStates(SystemAdmin_qbf5pt_EOImpl.java:262)
        at gov.epa.icis.sysadmin.server.ejb.SystemAdmin_qbf5pt_EOImpl_WLSkel.invoke(Unknown Source)
        at weblogic.rmi.internal.ServerRequest.sendReceive(ServerRequest.java:166)
        at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:284)
        at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:244)
        at gov.epa.icis.sysadmin.server.ejb.SystemAdmin_qbf5pt_EOImpl_813_WLStub.getStates(Unknown Source)
        at gov.epa.icis.sysadmin.ui.SysadminDelegate.getStates(SysadminDelegate.java:111)
        at gov.epa.icis.sysadmin.ui.action.AddUserAction.loadPage(AddUserAction.java:60)
        at gov.epa.icis.sysadmin.ui.action.AddUserAction.execute(AddUserAction.java:39)
        at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
        at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
        at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:996)
        at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419)
        at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:315)
        at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6452)
        at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
        at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
        at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3661)
        at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2630)
        at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
        at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)

_________________
- Chad


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 03, 2004 10:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Use your debugger and have a look at heuristicType() in net.sf.hibernate.type.TypeFactory - either your type class can not be found, or your class is wrong.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 04, 2004 10:08 am 
Beginner
Beginner

Joined: Sun Oct 03, 2004 8:50 am
Posts: 32
Location: McLean, VA
Thanks for the help on this Michael. Turns out the problem was neither. Instead Weblogic was caching some jar that didn't have the class in it. Problem resolved.

_________________
- Chad


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.