Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

length inconsistancies with SQL Server 2000

 
Praveen Kumar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

My journey with Hibernate is so bumpy. My backend database is SQL Server 2K. In the mapping files, for properties of type int I have a length restriction set and when the table is created, the field lengths are different.

mapping-file ....

<composite-id>
<key-property name="poNumber" type="long" column="po_number" />
<key-property name="revisionNumber" type="int" column="revision_number"length="2" />
</composite-id>

<property name="vendorNumber" column="vendor_num" type="int"
not-null="true" length="5"/>

In SQL server the field lengths of revisionNumber and vendorNumber are set to 4 and 4 respectively. I have no clue why this is happening and how to overcome it?

Any help would be highly appreciated.

Thanks,

Rave.
 
Praveen Kumar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess it looks like SQL server takes 4 bytes to store an integer. The value 4 represents the number of bytes and not the length of the field. Is there a way to tell to SQL server through Hibernate to create an int field that is of length 4 (max value: 9999 and min value: -9999).

Our client will be using Oracle when the system goes live. So I do not want to change a whole lot of data fields for Oracle.

Any suggestions?

Thanks,

Rave.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I guess it looks like SQL server takes 4 bytes to store an integer

I'm not sure that's true. Where did you find out that the <property /> element has a length attribute by the way - its not listed as an attribute in the Hibernate2 docs?

int datatypes in SQL Server always have a length of 4. Try using an Integer as your property type, and change the schema to use a bigint or numeric value.
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Rave"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You can change it

here.

Thanks! and welcome to the JavaRanch!

Mark
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!