-->
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: Create relations between two tables with <res>?
PostPosted: Fri Oct 05, 2007 9:48 am 
Newbie

Joined: Sat Sep 22, 2007 4:04 am
Posts: 7
Hello,

i have a MSSQL DB with two tables.
- table Resource(Res) contains infos like id, name,etc. of agents.
- table AgentStateDetail(Asd) logs the activity of the agents like busy,logged out, etc. One entry for each activity.

I would like to get agent Infos from table Res and the actually status of each agent from table Asd.

With native SQL i get what i want with this Query:
Code:
"select asd.eventDateTime, asd.eventType from db_cra.dbo.AgentStateDetail as asd CROSS JOIN db_cra.dbo.Resource res WHERE ( asd.eventDateTime = (SELECT MAX(asd2.eventDateTime) FROM db_cra.dbo.AgentStateDetail as asd2 WHERE asd2.agentID = res.resourceID)) AND (res.active = 1)   GROUP BY res.resourceID, res.extension, res.resourceName,res.resourceLoginID, asd.eventDateTime, asd.eventType"


Now i would like to use hibernate. My Colleague said i have to use the <set> command for this in the mapping file.

Seems like there is a problem with the primary keys of the table. Th beans and the mapping files were automatically generated by hibernate tools. Seems like there are no relations between the two tables. Is it possible to create them?
I have attached the mapping files, the res-Tag.

the Resource.hbm.xml looks like this:
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">
<!-- Generated 24.09.2007 10:24:30 by Hibernate Tools 3.2.0.b9 -->
<hibernate-mapping>
    <class name="mssql.Resource" table="Resource">
        <composite-id name="id" class="mssql.ResourceId">
            <key-property name="resourceId" type="int">
                <column name="resourceID" />
            </key-property>
            <key-property name="profileId" type="int">
                <column name="profileID" />
            </key-property>
        </composite-id>
        <property name="resourceLoginId" type="string">
            <column name="resourceLoginID" length="50" not-null="true" />
        </property>
....



th AgentStateDetail.hbm.xml looks like this:




Code:
<hibernate-mapping>
    <class name="mssql.AgentStateDetail" table="AgentStateDetail">
        <composite-id name="id" class="mssql.AgentStateDetailId">
            <key-property name="agentId" type="int">
                <column name="agentID" />
            </key-property>
            <key-property name="eventDateTime" type="timestamp">
                <column name="eventDateTime" length="23" />
            </key-property>
            <key-property name="eventType" type="byte">
                <column name="eventType" />
            </key-property>
            <key-property name="reasonCode" type="short">
                <column name="reasonCode" />
            </key-property>
            <key-property name="profileId" type="int">
                <column name="profileID" />
            </key-property>
        </composite-id>
        <property name="gmtOffset" type="short">
            <column name="gmtOffset" not-null="true" />
        </property>
.....


I have tried to enter follwing Set parameters in Resource.hbm.xml

Code:
<set name="agentStateDetails" inverse="true">
            <key>
   <column name="agentID"/>
   <column name="profileID"/>
            </key>
            <one-to-many class="mssql.AgentStateDetail" />
</set>



Code:
Compiling the code i get the following error:

15:37:27,328  INFO HbmBinder:2385 - Mapping collection: mssql.Resource.agentStateDetails -> AgentStateDetail
%%%% Error Creating HibernateSessionFactory %%%%
org.hibernate.MappingException: Foreign key (FK12A55C1DA5AE3C58:AgentStateDetail [agentID,profileID])) must have same number of columns as the referenced primary key (Resource [resourceID])
   at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:90)


I would be very glad about some help.

with kind regards

Martie


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 06, 2007 8:55 pm 
Regular
Regular

Joined: Sun Sep 30, 2007 7:51 pm
Posts: 93
What if you don't set the class for the composite id?
class="mssql.ResourceId"

Pavol


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.