-->
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: Problem with mapping
PostPosted: Sun Jun 08, 2008 8:50 pm 
Newbie

Joined: Sun Jun 08, 2008 8:04 pm
Posts: 1
Hibernate version: 3.2.4

Name and version of the database you are using: Oracle 10g

Mapping documents:

Activity.hbm.xml:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="com.example.Activity" table="ACTIVITY" lazy="false">
        <id name="activityKey" type="long">
            <column name="ACTIVITY_KEY"  />
            <generator class="sequence">
                <param name="sequence">ACTIVITY_KEY_SEQ</param>
            </generator>
        </id>
        <many-to-one name="activityType" class="com.example.ActivityType" fetch="join">
            <column name="ACTIVITY_TYPE_CD" precision="4" scale="0" not-null="true" />
        </many-to-one>
        <bag name="activityDetails" inverse="true" fetch="select" cascade="all,delete-orphan" lazy="false">
            <key>
                <column name="ACTIVITY_KEY" not-null="true" />
            </key>
            <one-to-many class="com.example.ActivityDetails" />
        </bag>
    </class>
</hibernate-mapping>


ActivityDetails.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class
        name="com.example.ActivityDetails"
        table="ACTIVITY_DETAILS" lazy="false">
        <id name="id" type="long">
            <column name="ID" />
            <generator class="sequence">
                <param name="sequence">ACTIVITY_DETAILS_ID_SEQ</param>
            </generator>
        </id>
        <many-to-one name="activity"
            class="com.example.Activity"
            fetch="join" not-null="true">
            <column name="ACTIVITY_KEY" not-null="true" />
        </many-to-one>
        <many-to-one name="activityDetailType"
            class="com.example.ActivityDetailType"
            fetch="join">
            <column name="DETAIL_TYPE_CD" not-null="true" />
        </many-to-one>
        <property name="detailValue" type="string">
            <column name="DETAIL_VALUE" length="2000" />
        </property>
    </class>
</hibernate-mapping>


ActivityMetadata.hbm.xml:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class
        name="com.example.ActivityMetadata"
        table="ACTIVITY_METADATA">
        <id name="id" type="long">
            <column name="ID" />
            <generator class="assigned" />
        </id>
        <property name="activityTypeCode" type="short">
            <column name="ACTIVITY_TYPE_CD" precision="4" scale="0" />
        </property>
        <property name="detailTypeCode" type="short">
            <column name="DETAIL_TYPE_CD" precision="4" scale="0" />
        </property>
        <property name="detailSeqNbr" type="short">
            <column name="DETAIL_SEQ_NBR" precision="4" scale="0" />
        </property>
        <property name="displayInd" type="short">
            <column name="DISPLAY_IND" precision="1" scale="0" />
        </property>
    </class>
</hibernate-mapping>


I'm having a slight issue with trying to map out what I thought would be a pretty simple mapping. I have 2 main tables (Activity and ActivityDetails). A third table (ActivityMetadata) contains a relationship between activity types and activity detail types.

Tables:
Activity:
ACTIVITY_KEY <-- primary key
ACTIVITY_TYPE_CD <-- this value can be duplicated

ActivityDetails (many to one relationship to Activity on ACTIVITY_KEY):
ID <-- primary key
ACTIVITY_KEY
DETAIL_TYPE_CD <-- this value can be duplicated
DETAIL_VALUE

ActivityMetadata:
ID <-- primary key
ACTIVITY_TYPE_CD
DETAIL_TYPE_CD
DETAIL_SEQ_NBR
DISPLAY_IND
(the combination of ACTIVITY_TYPE_CD and DETAIL_TYPE_CD is unique in this table)

What I'm wanting to do is get at the ActivityMetadata information from the level of the ActivityDetails. The join via sql would be like this:
Code:
select ad.*, am.detail_seq_nbr, am.display_ind
from activity_details ad, activity a, activity_metadata am
where ad.activity_key = a.activity_key
  and a.activity_type_cd = am.activity_type_cd
  and ad.detail_type_cd = am.detail_type_cd
  and ad.activity_key = ?


My ultimate goal is to be able to get the data from ActivityMetadata so that I can sort my results appropriately via HQL or Criteria. Any help would be greatly appreciated. I'm somewhat new to Hibernate, and although I've gone through the docs over and over, I just can't seem to figure this problem out!

If you need any further explanation, just ask. Thanks in advance!


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.