Hi all,
I could't figure out how to include my custom id generator, which may delegate work to the seqhilo generator, in the schema generate by hibernate (hbm2dll="create" when creating session factory).
When using de seqhilo directly, its tables are included in the schema as expected.
Thanks.
Here is the code for my generator:
Code:
public class GeneratedIdentifierGenerator implements IdentifierGenerator,
Configurable {
/**
* The delegate parameter specifies the underlying id generator to use.
*/
public static final String DELEGATE = "delegate";
private IdentifierGenerator assignedGenerator;
private IdentifierGenerator delegateGenerator;
/*
* (non-Javadoc)
*
* @see org.hibernate.id.IdentifierGenerator#generate(org.hibernate.engine.SessionImplementor,
* java.lang.Object)
*/
public Serializable generate(SessionImplementor session, Object object)
throws HibernateException {
if (object instanceof BoundedJavaBean) {
BoundedJavaBean bean = (BoundedJavaBean) object;
if (bean.getId() != null)
// The bean already has an id, so tell hibernate it is already
// assigned
return assignedGenerator.generate(session, object);
else
// Use the real generation strategy if no id was set for the
// bean
return delegateGenerator.generate(session, object);
} else {
// Use the real generation strategy if the object is not a
// BoundedJavaBean
return delegateGenerator.generate(session, object);
}
}
/*
* (non-Javadoc)
*
* @see org.hibernate.id.Configurable#configure(org.hibernate.type.Type,
* java.util.Properties, org.hibernate.dialect.Dialect)
*/
public void configure(Type type, Properties params, Dialect d)
throws MappingException {
String generatorName = params.getProperty(DELEGATE);
if (generatorName == null)
throw new MappingException(
"param named \"delegate\" is required for object generation strategy");
// Create the delegate and assigned id generators
delegateGenerator = IdentifierGeneratorFactory.create(generatorName,
type, params, d);
assignedGenerator = IdentifierGeneratorFactory.create("assigned", type,
params, d);
}
}
Hibernate version: 3.1.3
Mapping documents:Code:
<id name="id" type="long">
<generator class="com.estatcamp.sci.db.GeneratedIdentifierGenerator">
<param name="delegate">seqhilo</param>
<param name="sequence">hi_value_equipment</param>
<param name="max_lo">100</param>
</generator>
</id>
--------------------------
<id name="id" type="long">
<generator class="seqhilo">
<param name="sequence">hi_value</param>
<param name="max_lo">100</param>
</generator>
</id>
Full stack trace of any exception that occurs:
the following error happens because the seqhilo sequence and hi_value table were not created in the database
WARNING: SQL Error: -191, SQLState: S0002
01/06/2006 14:15:21 org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Sequence not found: HI_VALUE_EQUIPMENT in statement [select next value for hi_value_equipment from dual_hi_value_equipment]
org.hibernate.exception.SQLGrammarException: could not get next sequence value
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:96)
at org.hibernate.id.SequenceHiLoGenerator.generate(SequenceHiLoGenerator.java:53)
Name and version of the database you are using: hsqldb 1.8.0.3