Is it even possible to have Hibernate assign the id property of your POJO to the actual auto-incremented primary key id field in your database table?!?!
I already have a populated customers table with these fields:
- customer_id (integer, auto_increment)
- customer_name (varchar)
The customer_id field starts at 1 for the first customer and goes up from there to the last customer.
I created a Customer class that has these properties, along with appropriately named getters/setters:
- id (Long)
- name (String)
Now, I want Hibernate to create a Customer object for each row in the customers table, mapping the table fields to these POJO properties:
- customer_id ==> id
- customer_name ==> name
So I put this in the Customer.hbm.xml file:
Code:
<class name="Customer" table="customers">
<id name="id" column="customer_id">
<generator class="native"/>
</id>
<property name="name" column="customer_name"/>
</class>
However, when Hibernate creates the Customer objects, the id's ARE NOT the ones contained in the customers table. They are integers that start at 4294967297 and count up.
Can anyone tell me what stupid mistake or misunderstanding I'm making? I really want to use Hibernate, it looks super-cool, but I can't seem to get it to do this one really simple little thing.