views:

49

answers:

2

I know you can auto-increment an id by mapping;

<id column="user_id" name="id" >
<generator class="increment"/>
</id>

But is it also possible increment a property, what I tried so far didn't work;

<property column="numeric_value" name="nr" >
<generator class="increment"/>
</property>
A: 

It would depend on database and how you have created the table. For example if you are using Mysql, then in the table id field should have auto increment set for the field. Hibernate will not generate it, but rather depend on database to do it. If you use Hibernate tools to generate tables, it would take care of generating tables appropriately. You can refer to http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-declaration-id

Ck-
+1  A: 

But is it also possible increment a property, what I tried so far didn't work;

No, you can't use a <generator> inside a <property> (or, to write it in plain english, Hibernate only supports using a generator for identifier properties).

Maybe have a look at generated properties if you can rely on the database to generate the value (e.g. using a trigger).

References

Pascal Thivent