Reverse engineering uses hibernate type="int" in hbm.xml instead of "integer" for primary key column

Description

I have a table in SQL Server 2000 with the following properties:

Name: Case_ID
DataType: int
Length: 4
Allow Nulls: No

It is the primary key on the table and it uses the identity generator.

I created a hibernate.reveng.xml file and edit it in the Hibernate Reverse Engineering Editor.

The code for the file looks some like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >

<hibernate-reverse-engineering>

<table-filter match-catalog="DBName" match-schema="dbo"
match-name="Study" />
<table catalog="DBName" schema="dbo" name="Study">
<primary-key>
<generator class="identity"></generator>
</primary-key>
<column name="Column2" jdbc-type='' />
<!-- more columns here -->
</table>
</hibernate-reverse-engineering>

When it generates the hbm.xml file the code looks like this:

<id name="caseId" type="int">
<column name="Case_ID" />
<generator class="identity"></generator>
</id>

Therefore when I generate the .java code, the Java datatype is a primitive "int". This is not desired since the primary key column should be an object (java.lang.Integer in this case) and not a primitive. Shouldn't the type in the hbm.xml file default to "integer". I know that I can "fix" this behaviour by mapping the datatypes in the "Type Mappings" tab, but I wonder if this is what is intended and if it will frustrate other users. I also noticed a similar problem with the short datatype in that I had to explicitly use "java.lang.Short" when the column allows nulls. Otherwise the hbm2java did not map it correctly. If I am wrong about this, please let me know.

Environment

Hibernate 3.0, SQL Server 2000, jtds-1.2 driver

Activity

Show:

Steve Ebersole March 21, 2011 at 6:59 PM

Closing stale resolved issues

Max Rydahl Andersen March 31, 2006 at 5:29 PM

ok patrick, thanks for keep pushing me

I've implemented something now that is a bit more complete than just including in a flag for a primary key.
I've instead implemented a flag to tell if the column is a generated identifier (namely a non-natural id).

In this case the nullable version should be used, but if the key is of type "assigned" then it is a natural id
and shold never be null.

so that should keep you happy (as long as you specify a different strategy than assigned

Patrick Decat March 30, 2006 at 6:14 PM

My configuration :

  • DBMS : Sybase 12.0.0.5

  • JDBC driver : jConnect 6.05

Patrick Decat March 30, 2006 at 6:11 PM

I just checked out Hibernate3 and HibernetExt trunk and reproduced the problem.

Patrick Decat March 30, 2006 at 5:27 PM

Currently this method supports "isNullable", so we have:
nullable => object,
not-nullable => primitive type,
primary => not-nullable => primitive type

But we need:
nullable => object,
not-nullable => primitive type,
primary => object

Don't you agree ?

Fixed

Details

Assignee

Reporter

Bug Testcase Reminder (view)

Bug reports should generally be accompanied by a test case!

Bug Testcase Reminder (edit)

Bug reports should generally be accompanied by a test case!

Participants

Max Rydahl Andersen
Patrick Decat
Stefanie Liepmann
Steve Ebersole

Fix versions

Affects versions

Priority

Created March 6, 2006 at 5:34 PM
Updated March 21, 2011 at 6:59 PM
Resolved March 11, 2006 at 1:31 AM