-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Example for Programmatic Creation of Composite Id?
PostPosted: Mon Nov 24, 2008 8:54 am 
Newbie

Joined: Tue Nov 11, 2008 8:15 am
Posts: 2
Location: Europe, Germany, Somewhere
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.