I tried to assign ID for hibernate with double data type with this xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping >
<class name="User" table="user">
<id name="id" type="double" >
<column name="id_user" />
<generator class="increment" />
</id>
<property name="username" />
<property name="password" />
<property name="email" />
</class>
</hibernate-mapping>
but it gives me the error
org.hibernate.id.IdentifierGenerationException: Unknown integral data type for ids : java.lang.Double
at org.hibernate.id.IdentifierGeneratorHelper.getIntegralDataTypeHolder(IdentifierGeneratorHelper.java:210) at org.hibernate.id.IdentifierGeneratorHelper.getIntegralDataTypeHolder(IdentifierGeneratorHelper.java:210)
What's wrong with my code? Or is it a Hibernate bug or something?
Generating ids should be simple, using doubles for ids introduces complexity where it isn't needed. Hibernate is telling you not to use a double for ids, use an integer type (or a UUID or String). Basically you want to use something where comparisons are straightforward (which they aren't with floating point, see this question for how hairy comparisons can be). With floating point, comparisons are most straightforward between integer values, but why are you using floating point if you don't want digits following the decimal point?
The types you select in your mapping depend on the types used in the database. If you look at your schema usually the id's type is given as a fixed decimal numeric with a scale of zero (meaning the number cannot have a fractional part), because simple integer types may not be big enough for the number of inserts that the DBA expects. Since it's a fixed decimal JDBC will allow the id to be mapped to a floating point type, but that's not what you want here.
Fixed decimal and floating point are two different things. Fixed decimal means you have a fixed number of digits, where precision tells you how many digits before the decimal and scale tells you how many digits after the decimal point. Floating point means representing numbers using a complex binary representation (with strange things going on such as binary representation of some fractions resulting in repeating decimals that get truncated) that is a lot more complicated than what an id field needs.