{code} @Entity public class TestRow implements Serializable {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id;
@Id private Long version;
setters and getters are ommited for it's triviality } {code} 2. creating database and table by hand #mysql -u username ... create table F_TESTROW (ID bigint not null auto_increment, VERSION bigint not null, primary key (VERSION, ID))
TestRow testRow = new TestRow(); testRow.setVersion(2L); testRow.setAddr("somewhere"); sessionFactory.openSession().save(testRow);
produces java.lang.IllegalArgumentException: Can not set java.lang.Long field ru.kctsoft.fenestro.domain.strategy.TestRow.id to org.hibernate.id.IdentifierGeneratorHelper$2 at org.hibernate.property.DirectPropertyAccessor$DirectSetter.set(DirectPropertyAccessor.java:139)
This is kinda frustrating.
http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/ 2.2.3.2.4. Partial identifier generation
Hibernate supports the automatic generation of some of the identifier properties. Simply use the @GeneratedValue annotation on one or several id properties.
|