-->
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.  [ 4 posts ] 
Author Message
 Post subject: Metadata Composite key
PostPosted: Wed Feb 23, 2005 4:50 pm 
Beginner
Beginner

Joined: Mon Jun 21, 2004 2:41 pm
Posts: 40
I have been trying to get the Hibernate mapping metadata from the Configuration class for the last day and I have almost everything that I need except when it comes to getting the hibernate column name to database column name mapping.

I have looked at ClassMetadata, RootClass, SimpleValue, EntityPersister but I cannot find the API that I need.

The farthest I have been able to get is the database column's name but no corrilation of the Hibernate column name to the db name.

What have I missed?

Thank you very much,
David

Hibernate version: 2.1.7c

Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
   
<hibernate-mapping>
<!--
    Created by the Middlegen Hibernate plugin 2.1

    http://boss.bekk.no/boss/middlegen/
    http://www.hibernate.org/
-->

<class
    name="com.relevant.BizWiz.dao.Gag"
    table="gag"
>
    <meta attribute="class-description" inherit="false">
       @hibernate.class
        table="gag"
    </meta>

    <composite-id>
        <meta attribute="field-description" inherit="false">
           @hibernate.id
            generator-class="assigned"
        </meta>
        <key-property
            name="gagFamgroup"
            column="gag_famgroup"
            type="java.lang.String"
            length="8"
        >
            <meta attribute="field-description">
               @hibernate.property
                column="gag_famgroup"
                length="8"
            </meta>
        </key-property>
        <key-property
            name="gagFamilyid"
            column="gag_familyid"
            type="java.lang.String"
            length="20"
        >
            <meta attribute="field-description">
               @hibernate.property
                column="gag_familyid"
                length="20"
            </meta>
        </key-property>
    </composite-id>   

    <property
        name="gagComments"
        type="com.relevant.util.hibernate.StringType"
        column="gag_comments"
        not-null="true"
        length="200"
    >
        <meta attribute="use-in-tostring">true</meta>
        <meta attribute="field-description">
           @hibernate.property
            column="gag_comments"
            length="200"
            not-null="true"
        </meta>   
    </property>
    <property
        name="gagSeqno"
        type="short"
        column="gag_seqno"
        not-null="true"
        length="5"
    >
        <meta attribute="use-in-tostring">true</meta>
        <meta attribute="field-description">
           @hibernate.property
            column="gag_seqno"
            length="5"
            not-null="true"
        </meta>   
    </property>
    <property
        name="gagMsgno"
        type="com.relevant.util.hibernate.IntType"
        column="gag_msgno"
        not-null="true"
        length="10"
    >
        <meta attribute="use-in-tostring">true</meta>
        <meta attribute="field-description">
           @hibernate.property
            column="gag_msgno"
            length="10"
            not-null="true"
        </meta>   
    </property>
    <property
        name="gagLmdte"
        type="java.sql.Timestamp"
        column="gag_lmdte"
        length="23"
    >
        <meta attribute="use-in-tostring">true</meta>
        <meta attribute="field-description">
           @hibernate.property
            column="gag_lmdte"
            length="23"
        </meta>   
    </property>
    <property
        name="gagRbs"
        type="com.relevant.util.hibernate.StringType"
        column="gag_rbs"
        length="1"
    >
        <meta attribute="use-in-tostring">true</meta>
        <meta attribute="field-description">
           @hibernate.property
            column="gag_rbs"
            length="1"
        </meta>   
    </property>

    <!-- Associations -->
    <!-- derived association(s) for compound key -->
    <!-- end of derived association(s) -->

</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 3:41 pm 
Beginner
Beginner

Joined: Mon Jun 21, 2004 2:41 pm
Posts: 40
I failed to be more specific in that I cannot get the Hibernate to Db column name mapping information when I am trying to look at a column/field that is part of a composite key.

Anyone?

Thank you,
David


Top
 Profile  
 
 Post subject: Re: Metadata Composite key
PostPosted: Thu Feb 24, 2005 4:30 pm 
Newbie

Joined: Thu Feb 24, 2005 4:24 pm
Posts: 1
Same here....
But in my case I could only get Hibernate columns names (property names)......I desperately want know how can I get the mapping for db column name to hibernate column name.


Thanks,
Eknath Kadam


eldiosyeldiablo wrote:
I have been trying to get the Hibernate mapping metadata from the Configuration class for the last day and I have almost everything that I need except when it comes to getting the hibernate column name to database column name mapping.

I have looked at ClassMetadata, RootClass, SimpleValue, EntityPersister but I cannot find the API that I need.

The farthest I have been able to get is the database column's name but no corrilation of the Hibernate column name to the db name.

What have I missed?

Thank you very much,
David

Hibernate version: 2.1.7c

Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
   
<hibernate-mapping>
<!--
    Created by the Middlegen Hibernate plugin 2.1

    http://boss.bekk.no/boss/middlegen/
    http://www.hibernate.org/
-->

<class
    name="com.relevant.BizWiz.dao.Gag"
    table="gag"
>
    <meta attribute="class-description" inherit="false">
       @hibernate.class
        table="gag"
    </meta>

    <composite-id>
        <meta attribute="field-description" inherit="false">
           @hibernate.id
            generator-class="assigned"
        </meta>
        <key-property
            name="gagFamgroup"
            column="gag_famgroup"
            type="java.lang.String"
            length="8"
        >
            <meta attribute="field-description">
               @hibernate.property
                column="gag_famgroup"
                length="8"
            </meta>
        </key-property>
        <key-property
            name="gagFamilyid"
            column="gag_familyid"
            type="java.lang.String"
            length="20"
        >
            <meta attribute="field-description">
               @hibernate.property
                column="gag_familyid"
                length="20"
            </meta>
        </key-property>
    </composite-id>   

    <property
        name="gagComments"
        type="com.relevant.util.hibernate.StringType"
        column="gag_comments"
        not-null="true"
        length="200"
    >
        <meta attribute="use-in-tostring">true</meta>
        <meta attribute="field-description">
           @hibernate.property
            column="gag_comments"
            length="200"
            not-null="true"
        </meta>   
    </property>
    <property
        name="gagSeqno"
        type="short"
        column="gag_seqno"
        not-null="true"
        length="5"
    >
        <meta attribute="use-in-tostring">true</meta>
        <meta attribute="field-description">
           @hibernate.property
            column="gag_seqno"
            length="5"
            not-null="true"
        </meta>   
    </property>
    <property
        name="gagMsgno"
        type="com.relevant.util.hibernate.IntType"
        column="gag_msgno"
        not-null="true"
        length="10"
    >
        <meta attribute="use-in-tostring">true</meta>
        <meta attribute="field-description">
           @hibernate.property
            column="gag_msgno"
            length="10"
            not-null="true"
        </meta>   
    </property>
    <property
        name="gagLmdte"
        type="java.sql.Timestamp"
        column="gag_lmdte"
        length="23"
    >
        <meta attribute="use-in-tostring">true</meta>
        <meta attribute="field-description">
           @hibernate.property
            column="gag_lmdte"
            length="23"
        </meta>   
    </property>
    <property
        name="gagRbs"
        type="com.relevant.util.hibernate.StringType"
        column="gag_rbs"
        length="1"
    >
        <meta attribute="use-in-tostring">true</meta>
        <meta attribute="field-description">
           @hibernate.property
            column="gag_rbs"
            length="1"
        </meta>   
    </property>

    <!-- Associations -->
    <!-- derived association(s) for compound key -->
    <!-- end of derived association(s) -->

</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 4:57 pm 
Beginner
Beginner

Joined: Mon Jun 21, 2004 2:41 pm
Posts: 40
Eknath,

I am able to get the properties (normal fields/column) mapping just fine. Its the composite kiey fields that I cannot figure out how to do. Other than being evil and pasing the XML file directly.


This is the code snipe that I have to get the column mapping from a Property object:
Code:
//Class is a RootClass or PersistantClass instance
Property p = klass.getProperty(fieldName);
String result = getMetaColumnName(p);

private static String getMetaColumnName(Property p) {
      MetaAttribute attrib =  p.getMetaAttribute("field-description");
logger.info("attrib.getValues()" + attrib.getValues());
      String metaStr = attrib.getValue().trim();
      String [] lines = metaStr.split("\n");
      StringBuffer lineTmp= null;
      for (int i=0; i< lines.length; i++) {
logger.info("Looking at line = " + lines[i]);

         int loc = lines[i].indexOf("column=\"");
         if (loc != -1) {
            lineTmp = new StringBuffer(lines[i].substring(loc));
logger.info("lineTmp after new StringBuffer == " + lineTmp);

            int loc2 = lineTmp.indexOf("\"");
logger.info("loc2 = " + loc2);
            lineTmp.delete(0, loc2+1);
logger.info("lineTmp after first delete = " + lineTmp);
            loc2 = lineTmp.indexOf("\"");
logger.info("loc2 = " + loc2);
            lineTmp.delete(lineTmp.length()-1, lineTmp.length());
            
            break;
         }
      }
      
      return lineTmp.toString();
   }


It is not elligant and if the XML attribute name ever changes then my code will break :(

-David


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