-->
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.  [ 6 posts ] 
Author Message
 Post subject: Reverse engineering and sql-mapping with CHAR(1) to Integer
PostPosted: Thu Oct 26, 2006 2:20 am 
Newbie

Joined: Wed Oct 25, 2006 1:13 pm
Posts: 6
Hibernate version:3.2

i'm using the reverse engineeering ant task on an Oracle database (8.0).
I'm using oracle.jdbc.driver.OracleDriver.

My Oracle table is composed with a CHAR(1) attribute. The default mapping to Java is Character. i'would like to have Integer instead of ...

I'm using the:
<sql-type jdbc-type="CHAR" length="1" hibernate-type="integer"/>

and the resulted hbm.xml is

<property name="badpwd" type="integer">
<column name="BADPWD" length="1" />
</property>


The generated java is:

private Integer badpwd;

When i use the generated object: i'have the exception

26 oct. 2006 08:17:44 org.hibernate.type.NullableType nullSafeGet
INFO: could not read column value from result set: BADPWD10_0_; Echec de conversion dans la représentation interne
26 oct. 2006 08:17:44 org.hibernate.util.JDBCExceptionReporter logExceptions
ATTENTION: SQL Error: 17059, SQLState: null
26 oct. 2006 08:17:44 org.hibernate.util.JDBCExceptionReporter logExceptions
GRAVE: Echec de conversion dans la représentation interne
Exception in thread main
org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.JDBCException.<init>(JDBCException.java:26)
at org.hibernate.exception.GenericJDBCException.<init>(GenericJDBCException.java:19)
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2147)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
at org.hibernate.loader.Loader.list(Loader.java:2023)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:95)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at com.alcatel.in.osp.dao.GenericHibernateDAO.findByCriteria(GenericHibernateDAO.java:75)
at com.alcatel.in.osp.services.wms.dao.hibernate.CareHibernateDAO.find(CareHibernateDAO.java:18)
at com.alcatel.in.osp.services.wms.dao.hibernate.CareHibernateDAO.main(CareHibernateDAO.java:25)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 3:59 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
so oracle (understandably) doesn't like to convert char to numbers.

You will need a usertype for it (which you can specify as the hibernate-type in reveng.xml)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: How to implement UserType CHAR(1) to Integer ??
PostPosted: Fri Oct 27, 2006 3:07 am 
Newbie

Joined: Wed Oct 25, 2006 1:13 pm
Posts: 6
I have creacted my CharToIntegerUserType class overriding UserType class.

<type-mapping>
<sql-type jdbc-type="CHAR" length='1'>
<hibernate-type name="hibernate.Char1ToIntegerUserType"/>
</sql-type>
</type-mapping>

I run the revent ant task...and the generated java code has now:

private Char1ToIntegerUserType maxlengh; (maxlengh is CHAR(1))

How to have : private Integer maxlengh; ???

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 27, 2006 4:31 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
by having that type on the classpath so the codegen can ask it what Class it returns.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 31, 2006 1:30 pm 
Newbie

Joined: Wed Oct 25, 2006 1:13 pm
Posts: 6
Sorry but your answer is not clear for me....
My Char1ToIntegerUserType is in the classpath...The reveng is OK and the java files are generated...

The generated file:

import hibernate.Char1ToIntegerUserType;
import java.math.BigDecimal;

/**
* Care generated by hbm2java
*/
public class Care implements java.io.Serializable {

// Fields

private Long ri;
private Char1ToIntegerUserType badpwd;
private String login;
...

I would like to have

public class Care implements java.io.Serializable {

// Fields

private Long ri;
private Integer badpwd;
private String login;

Can you provide me a sample code to solve my pb ??

Regards,

Fred


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 31, 2006 4:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Char1ToIntegerUserType is *only* generated if one of two situations occor:

1) the usertype cannot be loaded by hbm2java to detect if its a usertype or not

2) the usertype returns Char1ToIntegerUserType in the getReturnedClass method.

I belive #1 is your case meaning it is *not* in the classpath of hibernatetool.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.