[hibernate-issues] [Hibernate-JIRA] Commented: (HBX-779) jdbc reengineer sql-type problem with oracle 9i

Raghunandan Sapre (JIRA) noreply at atlassian.com
Wed Apr 22 10:27:17 EDT 2009


    [ http://opensource.atlassian.com/projects/hibernate/browse/HBX-779?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=32983#action_32983 ] 

Raghunandan Sapre commented on HBX-779:
---------------------------------------

This issue is more relevant in UI where we want to bind a Long value to user interface and it shows 0 as default value if we use primitive long instead of NULL in case of java,lang.Long , as we get from hibernate default mapping. So people want to just do something to change long ->Long
as 
<sql-type jdbc-type="NUMERIC" precision='10' scale="0" hibernate-type="Long" /> 
<sql-type jdbc-type="DECIMAL" precision='10' scale="0" hibernate-type="Long" /> 
All This does not seem to work.

What seems to work in rev eng:
<sql-type jdbc-type="DECIMAL" precision='10' scale="0" hibernate-type="big_decimal" /> 

JDBC Reference: 
http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html

The recommended Java mapping for the DECIMAL and NUMERIC types is java.math.BigDecimal. 

Hibernate Types reference
http://svn.atlassian.com/fisheye/browse/~raw,r=21867/public/atlassian/vendor/hibernate-2.1.8/upstream/doc/api/net/sf/hibernate/type/BigDecimalType.html

big_decimal: A type that maps an SQL NUMERIC to a java.math.BigDecimal 
	
So the hibernate rev eng entry looks as follows and works.
<sql-type jdbc-type="DECIMAL" precision='10' scale="0" hibernate-type="big_decimal" /> 

			




> jdbc reengineer sql-type problem with oracle 9i
> -----------------------------------------------
>
>                 Key: HBX-779
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HBX-779
>             Project: Hibernate Tools
>          Issue Type: Bug
>          Components: reverse-engineer
>    Affects Versions: 3.2beta8
>         Environment: windowsxp sp2, jdk 1.4.2, eclipse 3.1.2
>            Reporter: jacky hua
>
> I used the ant task hibernate-tools provided like the below to generate hbms xml
>     <target name="default" description="generate hbm">
>     	<delete dir="./generate"/>
>     	<mkdir dir="./generate"/>
>         <hibernatetool destdir="./generate">
>         	<jdbcconfiguration 
>         		configurationfile="./metadata/hibernate.cfg.xml" 
>         		revengfile="./metadata/hibernate.reveng.xml"
>         		packagename="net.ema.examples.sa"
>         		detectmanytomany="true"
>         		detectoptimisticlock="true">
>         	</jdbcconfiguration>
>         	<hbm2hbmxml destdir="./generate" /> 
>         </hibernatetool>
>     </target>
> the ./metadata/hibernate.cfg.xml like the below:
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE hibernate-reverse-engineering 
>   SYSTEM "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
> <hibernate-reverse-engineering>
> 	<schema-selection match-catalog="TITAN" match-schema="TITAN" />
> 	<type-mapping>
> 		<!-- jdbc-type is name fom java.sql.Types -->
> 		<!-- length, scale and precision can be used to specify the mapping precisly -->
> 		<sql-type jdbc-type="NUMERIC" precision="1"
> 			hibernate-type="boolean" />
> 		<!-- the type-mappings are ordered. This mapping will be consulted last, 
> 			thus overriden by the previous one if precision=1 for the column -->
> 		<sql-type jdbc-type="NUMERIC" precision="19" hibernate-type="long" />
> 		<sql-type jdbc-type="TIMESTAMP" hibernate-type="java.util.Date" />
> 	</type-mapping>
> 	<!-- BIN$ is recycle bin tables in Oracle -->
> 	<table-filter match-name="BIN$.*" exclude="true" />
> </hibernate-reverse-engineering>
> But the <sql-type jdbc-type="NUMERIC" precision="19" hibernate-type="long" /> didn't work, also generate big_decimal type not long type, otherwise the others two sql-type rules worked. the not affected column:USER_ID was pk of my table. the generated hbm file is like the below:
>     <class name="net.ema.examples.sa.UserModel" table="T_SA_USER" schema="TITAN">
>         <id name="userId" type="big_decimal">
>             <column name="USER_ID" scale="0" />
>             <generator class="assigned" />
>         </id>
>         <property name="logonName" type="string">
>             <column name="LOGON_NAME" length="60" />
>         </property>
>         <property name="password" type="string">
>             <column name="PASSWORD" length="80" />
>         </property>
>         <property name="isOrgAdmin" type="java.lang.Boolean">
>             <column name="IS_ORG_ADMIN" precision="1" scale="0" />
>         </property>
>         <property name="remark" type="string">
>             <column name="REMARK" length="400" />
>         </property>
>         <property name="createDate" type="java.util.Date">
>             <column name="CREATE_DATE" length="11" />
>         </property>
>         <property name="status" type="string">
>             <column name="STATUS" length="2" />
>         </property>
>     </class>

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list