hbm2ddl doesn't create identity column with custom identifier generator
-----------------------------------------------------------------------
Key: HBX-910
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HBX-910
Project: Hibernate Tools
Type: Bug
Environment: hibernate 3.2.1 hsqldb 8.0.1
Reporter: Luca Dall'Olio
Priority: Minor
When defining a custom identifiergenerator which implements
org.hibernate.id.PostInsertIdentifierGenerator ,
hbm2ddl doesn't define the primary key column as identity (i.e.
hibernate.hbm2ddl.auto=create)
By looking at the source code, the hbm2dll depends on
org.hibernate.mapping.SimpleValue.isIdentityColumn() function, which in turn has a direct
dependency on IdentityGenerator.class :
public boolean isIdentityColumn(Dialect dialect) {
return
IdentifierGeneratorFactory.getIdentifierGeneratorClass(identifierGeneratorStrategy,
dialect)
.equals(IdentityGenerator.class);
}
in my opinion, it should depend instead on the PostInsertIdentifierGenerator interface :
public boolean isIdentityColumn(Dialect dialect) {
return
IdentifierGeneratorFactory.getIdentifierGeneratorClass(identifierGeneratorStrategy,
dialect)
.isInstance(PostInsertIdentifierGenerator.class);
}
Here is an example of a custom IdentityGenerator which can reproduce this problem :
package sample;
...
public class CustomIdentifierGenerator implements IdentifierGenerator,
PostInsertIdentifierGenerator {
private static IdentityGenerator hibernateGeneratorDelegate = null;
public Serializable generate(SessionImplementor session, Object object)
throws HibernateException {
return hibernateGeneratorDelegate.generate(session, object);
}
public InsertGeneratedIdentifierDelegate getInsertGeneratedIdentifierDelegate(
PostInsertIdentityPersister persister, Dialect dialect,
boolean isUseGet) throws HibernateException {
return hibernateGeneratorDelegate.getInsertGeneratedIdentifierDelegate(persister,
dialect, isUseGet);
}
}
Here an example mapping fragment :
<id name="id" type="long" column="DMM_ID">
<generator
class="sample.CustomIdentifierGenerator " />
</id>
--
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira