-->
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: Need Help with Composite Id and Many to One relationship
PostPosted: Sun Dec 11, 2005 7:15 pm 
Regular
Regular

Joined: Wed May 05, 2004 3:41 pm
Posts: 118
Location: New Jersey,USA
I'm having a problem with trying to get a many-to-one mapping working. My table structures are as below:
Code:
create table ISSUE_STATUS_MASTER
(
issue_status_id int not null,
issue_status_desc varchar(15),
primary key (issue_status_id)
)

create table issue_stat_history(
issue_status_id integer,
environment_id integer,
stat_date date,
issue_count integer,
primary key (issue_status_id,environment_id,stat_date)
)

create table ENVIRONMENT_MASTER
(
environment_id int not null,
environment_desc varchar(15),
primary key (environment_id)
)


Hibernate version: 3.0.3

Mapping documents:
IssueStatus.hmb.xml
Code:
<hibernate-mapping>
    <class name="com.tictrack.model.IssueStatus" table="ISSUE_STATUS_MASTER" schema="ANARASI">
        <id name="issueStatusId" type="integer">
            <column name="ISSUE_STATUS_ID" />
            <generator class="assigned" />
        </id>
        <property name="issueStatusDesc" type="string">
            <column name="ISSUE_STATUS_DESC" length="15" />
        </property>
        <property name="statusGroup" type="integer">
            <column name="STATUS_GROUP"/>
        </property>       
    </class>
    <query name="getAllStatus">
      from IssueStatus
    </query>         
</hibernate-mapping>


E3Environment.xml
Code:
<hibernate-mapping>
    <class name="com.tictrack.model.E3Environment" table="ENVIRONMENT_MASTER" schema="ANARASI">
        <id name="environmentId" type="integer">
            <column name="ENVIRONMENT_ID" />
            <generator class="assigned" />
        </id>
        <property name="environmentDesc" type="string">
            <column name="ENVIRONMENT_DESC" length="15" />
        </property>
    </class>
    <query name="getAllEnvironments">
      from E3Environment
    </query>   
</hibernate-mapping>

IssueStatistics.hbm.xml
Code:
<hibernate-mapping>
    <class name="com.tictrack.model.IssueStatistics"
           table="ISSUE_STAT_HISTORY" schema="ANARASI">
      
      <composite-id>
           <key-many-to-one name="issueStatus"
                     column="ISSUE_STATUS_ID"
                     class="com.tictrack.model.IssueStatus"/>       
           <key-many-to-one name="environment"
                     column="ENVIRONMENT_ID"
                     class="com.tictrack.model.E3Environment"/>       
           <key-property name="statsDate" type="date">
               <column name="STAT_DATE" not-null="true" />
           </key-property>
      </composite-id>
        <property name="issueCount" type="integer">
            <column name="ISSUE_COUNT" not-null="true" />
        </property>       
    </class> 

</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():
Session tSession = HibernateUtil.currentSession();
Query tQuery = tSession.createQuery("from IssueStatistics");
List tList = tQuery.list();
return tList;
Full stack trace of any exception that occurs:
Exception in thread "main" java.lang.ClassCastException: com.tictrack.model.IssueStatistics
at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:726)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:284)
at org.hibernate.loader.Loader.doQuery(Loader.java:395)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:210)
at org.hibernate.loader.Loader.doList(Loader.java:1562)
at org.hibernate.loader.Loader.list(Loader.java:1545)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:840)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at com.tictrack.dao.IssuesDAO.getIssueStats(IssuesDAO.java:195)
at E3TicketsTest.main(E3TicketsTest.java:40)
Name and version of the database you are using: Derby

The generated SQL (show_sql=true):
select issuestati0_.ISSUE_STATUS_ID as ISSUE1_, issuestati0_.ENVIRONMENT_ID as ENVIRONM2_, issuestati0_.STAT_DATE as STAT3_, issuestati0_.ISSUE_COUNT as ISSUE4_6_ from ANARASI.ISSUE_STAT_HISTORY issuestati0_
Debug level Hibernate log excerpt: DEBUG


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 11, 2005 7:23 pm 
Regular
Regular

Joined: Wed May 05, 2004 3:41 pm
Posts: 118
Location: New Jersey,USA
Found the issue. Did'nt include "implements java.io.Serializable". Silly mistake huh...Thanks.

-Anand


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.