-->
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.  [ 3 posts ] 
Author Message
 Post subject: Quck question: Composite-Id and named queries
PostPosted: Wed May 25, 2005 3:38 pm 
Newbie

Joined: Thu Sep 16, 2004 9:03 am
Posts: 8
Does hibernate support using named queries and composite-ids together?

I am having trouble getting it to work, and am wondering if it is a known limitation before I go through much more effort.

thanks,


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 25, 2005 7:33 pm 
Newbie

Joined: Thu Sep 16, 2004 9:03 am
Posts: 8
The reason I am asking, is because line 37 of the class "org.hibernate.loader.DefaultEntityAliases" returns the correct user established result set aliases when using a standard "id" property.

Ufortunately, when using a "composite-id" line 37 always returns null, which results in hibernate trying to alias the column names. I'm not sure if this is a bug, or my improper usage (probably the later).

Here is my mapping file:
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="pricemanagement.PriceManagementProposalStatistics" mutable="false">
           

        <composite-id>
           <key-property name="items"/>
            <key-property name="itemPercent"/>
           <key-property name="sales"/>
        </composite-id>
           
        <property name="salesPercent"/>
        <property name="incrementalGrossProfit"/>
        <property name="expectedGrossProfitPercent"/>
        <property name="grossProfitPercentDelta"/>
        <property name="type"/>
         
    </class>
   <sql-query name="GetPMProposalStatistics" callable="true">
       <return alias="proposalStatistics" class="pricemanagement.PriceManagementProposalStatistics">
           <return-property name="items" column="items"/>
           <return-property name="itemPercent" column="itemPercent"/>
           <return-property name="sales" column="sales"/>
           <return-property name="salesPercent" column="salesPercent"/>
           <return-property name="incrementalGrossProfit" column="incrementalGP"/>
           <return-property name="expectedGrossProfitPercent" column="expectedGPPercent"/>
           <return-property name="grossProfitPercentDelta" column="grossProfitPercentChange"/>
           <return-property name="type" column="statType"/>
       </return>
       {call GetRBPProposalStatistics(:projectKey, :userKey, :accountManagerKey) }
   </sql-query>
   
</hibernate-mapping>


And the error:
Code:
Hibernate: {call GetRBPProposalStatistics(?, ?, ?) }
[WARN] JDBCExceptionReporter - SQL Error: 0, SQLState: 42S22
[ERROR] JDBCExceptionReporter - [Microsoft][SQLServer 2000 Driver for JDBC]Invalid column name: items0_
Exception in thread "main" org.springframework.jdbc.BadSqlGrammarException: Bad SQL grammar [] in task 'Hibernate operation'; nested exception is java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid column name: items0_
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid column name: items0_
   at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
   at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
   at com.microsoft.jdbc.base.BaseResultSet.getColumnOrdinal(Unknown Source)
   at com.microsoft.jdbc.base.BaseResultSet.getInt(Unknown Source)
   at org.apache.commons.dbcp.DelegatingResultSet.getInt(DelegatingResultSet.java:236)
   at org.hibernate.type.IntegerType.get(IntegerType.java:26)
   at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:77)
   at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:68)
   at org.hibernate.type.AbstractType.hydrate(AbstractType.java:80)
   at org.hibernate.type.ComponentType.hydrate(ComponentType.java:423)
   at org.hibernate.type.ComponentType.nullSafeGet(ComponentType.java:182)
   at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:759)
   at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:292)
   at org.hibernate.loader.Loader.doQuery(Loader.java:412)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
   at org.hibernate.loader.Loader.doList(Loader.java:1593)
   at org.hibernate.loader.Loader.list(Loader.java:1577)
   at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:112)
   at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1414)
   at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:153)


Thanks for any help...


Top
 Profile  
 
 Post subject: Got solution
PostPosted: Wed Oct 05, 2005 11:47 am 
Senior
Senior

Joined: Wed Aug 17, 2005 12:56 pm
Posts: 136
Location: Erie, PA (USA)
Hibernate 3.0.5.

I have seen many questions/issues about this. Here is a solution:

Mapping document:
---------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="test.MyView">
<composite-id>
<key-property name="mdrId" type="java.lang.Integer" />
<key-property name="sourceCode" type="java.lang.String" />
</composite-id>
<property name="tranDate" update="false" insert="false" type="java.util.Date" />
<property name="statistic" update="false" insert="false" type="java.lang.Float" />
</class>
<sql-query name="namedQuery">
query text OR stored procedure call
<return alias="m" class="test.MyView" >
<return-property name="id">
<return-column name="mdrId" />
<return-column name="sourceCode" />
</return-property>
<return-property name="tranDate" column="tranDate" />
<return-property name="statistic" column="statistic" />
</return>
</sql-query>
</hibernate-mapping>
---------------------------------
The trick seems to be using "id" to reference the unnamed composite-id element. This works for either an SQL query or a stored procedure call. I hope this helps.

Curtis ...


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