-->
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.  [ 5 posts ] 
Author Message
 Post subject: Property iterator for composite IDs ?
PostPosted: Tue Aug 17, 2004 11:40 pm 
Beginner
Beginner

Joined: Wed Jan 28, 2004 3:42 pm
Posts: 36
Hibernate version:2.1.6

mapping:
Code:
    <composite-id name="comp_id" class="PTAPK">
        <meta attribute="default-value">new PTAPK()</meta>
        <key-property
            name="finCoaCd"
            column="FIN_COA_CD"
            type="java.lang.String"
            length="8"
        >
                <meta attribute="default-value">null</meta>
        </key-property>
        <key-many-to-one name="project" class="Project">
                <meta attribute="default-value">new Project()</meta>
                <column name="PROJECT_CD" />
        </key-many-to-one>
        <key-property
            name="taskCd"
            column="TASK_CD"
            type="java.lang.String"
            length="8"
        >
                <meta attribute="default-value">null</meta>
        </key-property>
        <key-many-to-one name="award" class="Award">
                        <meta attribute="default-value">new Award()</meta>
                        <column name="AWARD_CD"/>
        </key-many-to-one>
    </composite-id>



Hi,

I am trying to build a list of the properties inside a composite key, I cannot see a clear way on how to do this? I can only get as far as getColumnIterator() which does not give me the required information (actually java property/accessor name).

getConfiguration().getClassMapping(theclass).getIdentifierProperty().getColumnIterator();

Also with Column.getType(), only isComponentType seems to be true all the time, even though some columns in aforementioned composite key are references to other objects, isAssociation et al are all false:


Code:
         Property idProperty = BaseInit.getConfiguration().getClassMapping(name).getIdentifierProperty();
         Type idPropertyType = s.getSessionFactory().getClassMetadata(name).getIdentifierType();

         if (idProperty.isComposite())
         {
            log.info("Found composite PK! " + idProperty.getName() + " - " + idPropertyType.getReturnedClass().getName());
            Iterator ite = idProperty.getColumnIterator();
            while (ite.hasNext())
            {
               Column col = (Column)ite.next();
               if (col.getType().isAssociationType())
                  log.info("Found a nested association type! " + col.getName());

               if (col.getType().isComponentType())
                  log.info("Found a nested component type! " + col.getName());

               if (col.getType().isEntityType())
                  log.info("Found a nested entity type! " + col.getName());

               if (col.getType().isPersistentCollectionType())
                  log.info("Found a persistent collection type! " + col.getName());

               if (col.getType().isObjectType())
                  log.info("Found a object type! " + col.getName());
            }


Thanks for any advice,
Peter


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 28, 2004 8:06 am 
Beginner
Beginner

Joined: Mon Mar 22, 2004 10:01 am
Posts: 22
I have the same problem, I've created a Echo based web UI that can display any hibernate mapping (it works trough metadata, which I extract from the Hibernate metadata).

For that I need all the metadata from Hibernate, but I can't handle composite-id with a single element, for example a key-meny-to-one.

The problem is that the mapping does not create a Property for composite-id, even tough if it has a single key-many-to-one it look like a simple many-to-one on the Mapping level, only it would be the idProperty too.

If you have a composite-id, which has a name and a type (a user Key class), then a property is created, but noone will map my case with a user Key object.

I'm working with the Hibernate3 branch.


Please Hibernate team, is there any chance that the following mapping creates a property with the name "user", just like a simple many-to-one would? And that PersistentClass.getIdProperty() returns non-null?

<composite-id>
<key-many-to-one name="user" column="userId"/>
</composite-id>

Or is there something else I'm missing here?

Thanks in advance!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 28, 2004 11:07 am 
Beginner
Beginner

Joined: Mon Mar 22, 2004 10:01 am
Posts: 22
hmm... a top level <id-many-to-one> would also solve my problem.

or a more general <many-to-one name="user"> and an <id-designator name="user">

Could any of these work?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 29, 2004 10:17 pm 
Beginner
Beginner

Joined: Wed Jan 28, 2004 3:42 pm
Posts: 36
I think I found the solution, here's a quick snippet:

Code:
        PersistentClass pclass = configuration.getClassMapping(ExpenseArea.class);
        Property componentProperty = pclass.getIdentifierProperty();
         
         Value value = componentProperty.getValue();
         if (value == null)
            System.out.println("The value is NULLL!!!!!!");
         else
         {
            if (value instanceof Component)
            {
               Component component = (Component)value;
               
               System.out.println("the compoment has " + component.getPropertySpan() + " properties");
               Iterator ite = component.getPropertyIterator();
               while (ite.hasNext())
               {
                  Property property = (Property)ite.next();
                  System.out.println("property name: " + property.getName());
               }
            }
            else
            {
               System.out.println("The value is not a component :( :( ");
            }
         }


Hope that helps somebody,
Peter


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 01, 2004 9:45 am 
Beginner
Beginner

Joined: Mon Mar 22, 2004 10:01 am
Posts: 22
Great, thanks a lot!

Now I can remove the last traces of speacial-casing...

If only the metadata in H were not that ad-hoc, based on relational data model needs.

Thanks again!


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

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.