-->
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: many-to-one classCastException on query.
PostPosted: Thu Oct 27, 2005 2:56 pm 
Newbie

Joined: Thu Mar 24, 2005 10:07 am
Posts: 14
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Im really hoping someone can help me. This might be a newbie question but I have a situation where I fear there will be performance issues. I have an auction scenario.

An Auction contains a Set of Bids. Bids are tied directly to Invesotrs

So it looks like Auction -->Bid <-- Investor

The problem is that I want to be able to query only partial information from the Bid, NOT the whole Bid. Getting the whole bid means getting the whole Investor and Auction which inturn have thier own collections of collections and it slows everything down.

I want to know specifically 1 thing. Is there a way to query this object for only certain fields without using JDBC. Or is there a way to not allow the Bid object return anything but the ID of the the many to one Investor Obj or Company Obj.




Hibernate version: 2.1.7

Mapping documents:

Bid Object is tied to Investor and Auction
mapping in question for an object that has direct ties to 2 other objects:

<class name="com.imediainc.pcmexchange.databeans.BidBean" table="tbl_Bids">
<meta attribute="class-description">

</meta>

<id name="BidID" type="int" column="BidID">
<generator class="vm" />
</id>
<many-to-one name="InvestorID" class="com.imediainc.pcmexchange.databeans.InvestorBean" update="true" outer-join="true"/>
<many-to-one name="AuctionID" class="com.imediainc.pcmexchange.databeans.AuctionBean" update="true" cascade="none" outer-join="true" />
<property name="BidDate" type="timestamp" />
<property name="BidAmount" type="double" not-null="true" />
<property name="AutoBidAmount" type="double" />
<property name="AutoBidIncrement" type="int" />
<property name="IsWinningBid" type="boolean" />
</class>

The following query works and grabs entire InvestorBean and entire AuctionBean.
But the problem is each of these objects has large collections themselves and the wait time is HUGE.

<query name="com.imediainc.pcmexchange.queries.getThinBidByID">
<![CDATA[
from com.imediainc.pcmexchange.databeans.BidBean as b
where b.BidID=:BidID
]]>
</query>

This query however would give me the specific data i wanted without all the other objects and thier own collections but if fails with a class cast exception
<query name="com.imediainc.pcmexchange.queries.getThinBidByID">
<![CDATA[
select b.BidID, b.BidDate, b.BidAmount
from com.imediainc.pcmexchange.databeans.BidBean as b
where b.BidID=:BidID
]]>
</query>


Code between sessionFactory.openSession() and session.close():

zTransaction = zSession.beginTransaction();

Query zQuery = zSession.getNamedQuery("com.imediainc.pcmexchange.queries.getThinBidByID");

zQuery.setInteger("BidID", iBid_p);


zLogger.debug("PCMEXCHANGE EXCEPTION:: About to get result: ");
zFoundBid = (BidBean)zQuery.uniqueResult();
zLogger.debug("PCMEXCHANGE EXCEPTION:: Got result: ");
//zLogger.debug("PCMEXCHANGE EXCEPTION:: Bid: " + zFoundAuction.getAuctionID());
zTransaction.commit();

Full stack trace of any exception that occurs:


14:06:33,312 DEBUG HibernateUtil:? - PCMEXCHANGE:: GETTING SESSION FROM THREAD
14:06:33,312 DEBUG HibernateUtil:? - PCMEXCHANGE:: SESSION WAS NULL, MAKING NEW:
14:06:33,312 DEBUG SessionImpl:560 - opened session
14:06:33,328 DEBUG JDBCTransaction:37 - begin
14:06:33,328 DEBUG JDBCTransaction:41 - current autocommit status:true
14:06:33,328 DEBUG JDBCTransaction:43 - disabling autocommit
14:06:33,343 DEBUG PCMExchangeData:? - PCMEXCHANGE EXCEPTION:: About to get result:
14:06:33,343 DEBUG SessionImpl:1537 - find:

select b.BidID, b.BidDate, b.BidAmount
from com.imediainc.pcmexchange.databeans.BidBean as b
where b.BidID=:BidID


14:06:33,359 DEBUG QueryParameters:122 - named parameters: {BidID=1}
14:06:33,390 DEBUG QueryTranslator:147 - compiling query
14:06:33,421 DEBUG SessionImpl:2267 - flushing session
14:06:33,421 DEBUG SessionImpl:2467 - Flushing entities and processing referenced collections
14:06:33,421 DEBUG SessionImpl:2808 - Processing unreferenced collections
14:06:33,421 DEBUG SessionImpl:2822 - Scheduling collection removes/(re)creates/updates
14:06:33,421 DEBUG SessionImpl:2291 - Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects
14:06:33,421 DEBUG SessionImpl:2296 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
14:06:33,421 DEBUG SessionImpl:1828 - Dont need to execute flush
14:06:33,421 DEBUG QueryTranslator:207 - HQL:

select b.BidID, b.BidDate, b.BidAmount
from com.imediainc.pcmexchange.databeans.BidBean as b
where b.BidID=:BidID


14:06:33,421 DEBUG QueryTranslator:208 - SQL: select bidbean0_.BidID as x0_0_, bidbean0_.BidDate as x1_0_, bidbean0_.BidAmount as x2_0_ from tbl_Bids bidbean0_ where (bidbean0_.BidID=? )
14:06:33,437 DEBUG BatcherImpl:204 - about to open: 0 open PreparedStatements, 0 open ResultSets
14:06:33,437 DEBUG SQL:230 - select bidbean0_.BidID as x0_0_, bidbean0_.BidDate as x1_0_, bidbean0_.BidAmount as x2_0_ from tbl_Bids bidbean0_ where (bidbean0_.BidID=? )
14:06:33,437 DEBUG BatcherImpl:253 - preparing statement
14:06:33,453 DEBUG IntegerType:46 - binding '1' to parameter: 1
14:06:33,484 DEBUG Loader:281 - processing result set
14:06:33,500 DEBUG Loader:484 - result row:
14:06:33,500 DEBUG IntegerType:68 - returning '1' as column: x0_0_
14:06:33,500 DEBUG TimestampType:68 - returning '2005-04-05 00:00:00' as column: x1_0_
14:06:33,500 DEBUG DoubleType:68 - returning '444.0' as column: x2_0_
14:06:33,500 DEBUG Loader:298 - done processing result set (1 rows)
14:06:33,500 DEBUG BatcherImpl:211 - done closing: 0 open PreparedStatements, 0 open ResultSets
14:06:33,500 DEBUG BatcherImpl:275 - closing statement
14:06:33,500 DEBUG SessionImpl:3161 - initializing non-lazy collections
14:06:33,500 DEBUG PCMExchangeData:? - PCMEXCHANGE EXCEPTION:: getThinBidByID(): java.lang.ClassCastException

14:06:33,500 DEBUG JDBCTransaction:82 - rollback
14:06:33,515 DEBUG SessionImpl:596 - transaction completion
14:06:33,515 DEBUG JDBCTransaction:103 - re-enabling autocommit
14:06:33,515 DEBUG HibernateUtil:? - PCMEXCHANGE:: CLOSING SESSION
14:06:33,515 DEBUG HibernateUtil:? - PCMEXCHANGE:: SESSION WAS NOT NULL, CLOSING:
14:06:33,515 DEBUG SessionImpl:578 - closing session
14:06:33,515 DEBUG SessionImpl:3383 - disconnecting session
14:06:33,531 DEBUG SessionImpl:596 - transaction completion
14:06:33,546 DEBUG SessionImpl:3435 - running Session.finalize()
Oct 27, 2005 2:12:24 PM org.apache.coyote.http11.Http11Protocol pause
INFO: Pausing Coyote HTTP/1.1 on http-8080



Name and version of the database you are using: MSSQL with jtds driver and c3po connection pool

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt: debug


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.