Hello all,
I'm trying to get a solution for a multiple table mapping (if you are interested in the underlying problem, please have a look at my other post,
http://forum.hibernate.org/viewtopic.php?t=992246*).
What I'd like to know is how one programmatically can create a composite id and apply it to a
PersistentClass object which then is applied to a
Configuration object.
I've already checked
Java Persistence with Hibernate, Ch. 3.3.5, p. 139 et sqq. where you can see how to modify an existing
Configuration object by adding another Column to a PersistentClass and then create a new
SessionFactory from it.
I couldn't find anything comparable in the
Reference Documentation (vers. 3.3.1.GA) and the Javadoc of the "candidate classes" (
PersistentClass,
Component,
Property etc.) is rather minimalistic ;-) Search engines investigation also wasn't successfull :-|
My first approach would roughly look like:
Code:
Component identifierComponent = new Component(persistentClass);
Property additionalKeyProperty = new Property();
if (null == persistentClass.getIdentifierMapper())
{
// Add the existing ID property of a single-key entity identifierComponent.addProperty(persistentClass.getIdentifierProperty());
// create the next ID property
additionalKeyProperty .setName("additionalKey");
additionalKeyProperty .setNodeName("additionalKey");
additionalKeyProperty .setPersistentClass(persistentClass);
additionalKeyProperty .setOptional(false);
identifierComponent.addProperty(additionalKeyProperty);
/* Possible candidates: */
/* identifierComponent.createIdentifierGenerator(dialect, defaultCatalog, defaultSchema, rootClass)
identifierComponent.addTuplizer(entityMode, implClassName)
identifierComponent.setKey(isKey) */
// later: NPE PropertyFactory.buildStandardProperty()
persistentClass.setIdentifierMapper(identifierComponent);
The code above results in a
NullPointerException in
org.hibernate.tuple.PropertyFactory.buildStandardProperty() >/*
Has anybody done this before and is willing to share her/his knowledge?
Any other hints (e.g. to other documentation, learn source code by heart)?
Thanks and kind regards from Europe, Germany, Berlin,
Karsten
* Which is
no crosspost as though the problem behind both posts is the same, the technical solution approach is completely different.