[hibernate-issues] [Hibernate-JIRA] Created: (HHH-6044) Compound ID with auto-generated part produces exception

Alex Shubert (JIRA) noreply at atlassian.com
Wed Mar 23 10:00:08 EDT 2011


Compound ID with auto-generated part produces exception
-------------------------------------------------------

                 Key: HHH-6044
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6044
             Project: Hibernate Core
          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.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list