[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-6044) Compound ID with auto-generated part produces exception
Alex Shubert (JIRA)
noreply at atlassian.com
Tue May 15 10:27:12 EDT 2012
[ https://hibernate.onjira.com/browse/HHH-6044?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=46671#comment-46671 ]
Alex Shubert commented on HHH-6044:
-----------------------------------
Anne Buit Documentation states, Hibernate team do not consider such a keys a good idea. Trust expert's opinion and find a way to implement your strategy in a different way.
> Compound ID with auto-generated part produces exception
> -------------------------------------------------------
>
> Key: HHH-6044
> URL: https://hibernate.onjira.com/browse/HHH-6044
> Project: Hibernate ORM
> Issue Type: Bug
> Components: core
> Affects Versions: 3.5.6
> Environment: java 6.23 64bit
> Hibernate 3.5.6
> Reporter: Alex Shubert
>
> @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
> }
> 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.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list