I have an table with cars:
- CarId
- CustomerId
- ...
The mapping file looks like this:
<hibernate-mapping>
<class name="org.project.Car" table="tblCar">
<id name="id" column="CarId" type="int">
<generator class="native"/>
</id>
<property column="CustomerId" name="customerId" type="text"/>
<many-to-one column="CustomerId" name="customer" class="org.project.Customer" insert="false" update="false" fetch="select"/>
...
</class>
</hibernate-mapping>
The problem lies in the many-to-one column: When I remove it, I can load all the cars. When it's there, I get the following error:
INFO: could not read column value from result set: Cus2_3_0_; Value 00005-C cannot be converted to INTEGER.
, whereas 00005-C is the Id of a customer.
Why on earth does Hibernate want to cast the customerId column to integer when it says text? Or can I only use integer IDs for foreign keys?
Edit: My customer mapping roughly looks like this:
<hibernate-mapping>
<class name="org.project.Customer" table="tblCustomer">
<id name="id" column="Id" type="integer">
<generator class="native"/>
</id>
<property column="CustomerId" name="customerId" type="text"/>
...
<set name="cars" inverse="true" lazy="true" fetch="select">
<key column="CustomerId" not-null="true"/>
<one-to-many class="org.project.Car"/>
</set>
</class>
</hibernate-mapping>