Hernan,
Thanks! This concatenated key strategy worked wonderfully. I've shared my own code below.
Adam: The de-normalized nature of this solution is a bit of a drawback, do you see any chance that the VersionEntity could easily support a composite @Embeddable @Id, @IdClass, or @EmbeddedId style solution without too much effort? (With a few pointers I'd volunteer to write a patch, but don't want to dive into entropy like in my comment http://community.jboss.org/message/528334#528334 above)
In the @RevisionEntity I put this mapping:
@Id
@GeneratedValue(generator="versionIdGenerator")
@GenericGenerator(name="versionIdGenerator", strategy="com.xyz.db.hibernate.version.VersionIdGenerator")
@RevisionNumber
protected Long id;
Here is the code from VersionIdGenerator.java. This probably won't work for "select after insert" style generators, but will pick up the native generator:
public class VersionIdGenerator implements IdentifierGenerator, Configurable
{
IdentifierGenerator nativeGenerator;
public VersionIdGenerator()
{
}
@Override
public Serializable generate(SessionImplementor session, Object obj) throws HibernateException
{
MasterVersionHistory masterVersionHistory = (MasterVersionHistory)obj;
long nativeGenerate = (Long) nativeGenerate(session, obj);
masterVersionHistory.originalId = nativeGenerate;
long modulo = nativeGenerate % 10000;
long date = masterVersionHistory.date;
long result = date*10000 + modulo;
return result;
}
protected Serializable nativeGenerate(SessionImplementor session, Object obj)
{
return nativeGenerator.generate(session, obj);
}
@Override
public void configure(Type type, Properties params, Dialect dialect) throws MappingException
{
this.nativeGenerator = IdentifierGeneratorFactory.create("native", type, params, dialect);
}
}
Hello,
unfortunately, after some though, this hits the same problems as the original considerations: even if composite ids for revision entities are supported, how do you order them? You need the notion of ">" and "<", and that's most probably defined by some lexygraphic sorting. So encoding such two numbers into one is the best solution for now, I think.
Adam