문제

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>
도움이 되었습니까?

해결책

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

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top