-->
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.  [ 2 posts ] 
Author Message
 Post subject: Find mappings for Hibernate
PostPosted: Mon Nov 20, 2006 6:41 pm 
Newbie

Joined: Mon Nov 20, 2006 6:30 pm
Posts: 3
Hi guys!

I'm new to Hibernate, I'm composing some HQl dynamically and I need to find the corresponding mapping of TABLE_NAME and COLUMN_NAME to objectType and propertyName at runtime.

To be clearer, let's exemplify with an excerpt from one of the Hibernate mapping files:

Code:
.......................
<hibernate-mapping>
  <class table="PACKAGES" lazy="false" schema="HSTANCIU" name="com.esi.packages.model.Package">
    <id name="id" column="PACKAGE_SK">
<!-- @todo: change the generator with sequence -->   
      <generator class="increment"/>
    </id>
    <timestamp column="last_update_dttm" unsaved-value="null" name="lastUpdateDTTM"/>
    <property name="code" column="package_code"/>
    <property name="name" column="package_name"/>   
.............
</hibernate-mapping>

So, I know at runtime

TABLE_NAME = "PACKAGES"

and

COLUMN_NAME ="package_name"

I need to find the type and property name associated with this mapping. In my case this would be

"com.esi.packages.model.Package"

respective

"name"

Thank you for any idea.

Regards,
Horatiu


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 21, 2006 4:00 pm 
Newbie

Joined: Mon Nov 20, 2006 6:30 pm
Posts: 3
I suceed to get the object name in a way, I need to also get the property name of the object, having the column name.

For getting the object name I used this:

Code:
[b]String searchedTable="given_table";
        String searchedColumn="given_column";[/b]
        Iterator itClassMappings = cfg.getClassMappings();
        PersistentClass pc = null;
        String tableName = null;
        Column column = null;
        Table table = null;
        while (null != itClassMappings && itClassMappings.hasNext()){
            pc = (PersistentClass)itClassMappings.next();
            table = pc.getTable();
            tableName = table.getName();
            // check if the table is the one I'm looking for
            if( searchedTable.equals(tableName) ){

                    column = new Column(searchedColumn);
                    column = table.getColumn(column);
                   [b] System.out.println("Object name =["+pc.getClassName() +"]");       [/b]
                  //
                  // Now I need to get the object's attribute where searchedColumn is mapped to
                  //
                 [b] System.out.println("HELP! Any ideas?");       [/b]
            }
               
            }


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.