-->
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.  [ 5 posts ] 
Author Message
 Post subject: what's wrong with my code using "select new ClassName(.
PostPosted: Sat Apr 10, 2004 9:01 pm 
Regular
Regular

Joined: Sat Apr 10, 2004 8:39 pm
Posts: 84
Changes in version 2.1.2 (4.2.2004)
* queries with "select new" now cacheable
===============================
my code:
----------------------------------------
Query query=ss.createQuery(
select new ClassName({tableName}.x}) from TableName as {tableName} where ...
);

my code break on

Iterator iter = query.list().iterator();

error message is about something wrong on sql server...........


================================
what's wrong with my code using "select new ClassName(...

/**
* Demonstrates HQL projection/aggregation
*/
public void viewAllAuctionsFast() throws Exception {
System.out.println("Viewing all auction item info");

Session s = factory.openSession();
Transaction tx=null;
try {
tx = s.beginTransaction();

List auctions = s.createQuery(
"select new AuctionInfo( item.id, item.description, item.ends, max(bid.amount) ) "
+ "from AuctionItem item "
+ "left join item.bids bid "
+ "group by item.id, item.description, item.ends "
+ "order by item.ends desc"
)
.setMaxResults(100)
.list();

Iterator iter = auctions.iterator();
while ( iter.hasNext() ) {
AuctionInfo ai = (AuctionInfo) iter.next();
System.out.println(
"Auction: " + ai.getId() + " - " + ai.getDescription() +
", ends: " + ai.getEnds() +
", highest bid: " + ai.getMaxAmount()
);
}
System.out.println();

tx.commit();
}
catch (Exception e) {
if (tx!=null) tx.rollback();
throw e;
}
finally {
s.close();
}
}

_________________
I am the creatxr of world.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 11, 2004 6:07 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
This {tableName}.x} stuff is surely not a legal HQL query. What is the error message besides, and take a look at the generate SQL.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 11, 2004 8:50 pm 
Regular
Regular

Joined: Sat Apr 10, 2004 8:39 pm
Posts: 84
System.out.println ("11111111111111");
Query query2 = session.createQuery("select {wsHdzsSp}.spjgDm from WsHdzsSp as {wsHdzsSp} where {wsHdzsSp}.nsrsbh=:nsrsbh and {wsHdzsSp}.wspzxh=:wspzxh" );
query2.setString("nsrsbh", nsrsbh);
query2.setString("wspzxh", wspzxh);
Iterator iter2 = query2.list().iterator();
System.out.print("2222222222");
while (iter2.hasNext()) {
VTest row = (VTest) iter2.next();
System.out.println(row.getSpjgDm());
}
System.out.println ("success...........");

============================================
11111111111111
08:47:21,676 WARN JDBCExceptionReporter:20 - SQL Warning: 0, SQLState:
08:47:21,676 WARN JDBCExceptionReporter:28 - [Microsoft][SQLServer 2000 Driver
for JDBC]Database changed to ctais_oracle
08:47:21,676 WARN JDBCExceptionReporter:20 - SQL Warning: 0, SQLState:
08:47:21,676 WARN JDBCExceptionReporter:28 - [Microsoft][SQLServer 2000 Driver
for JDBC][SQLServer]已将数据库上下文改为 'ctais_oracle'。
08:47:21,686 WARN JDBCExceptionReporter:20 - SQL Warning: 0, SQLState:
08:47:21,686 WARN JDBCExceptionReporter:28 - [Microsoft][SQLServer 2000 Driver
for JDBC]Language changed to 简体中文
08:47:21,696 WARN JDBCExceptionReporter:20 - SQL Warning: 0, SQLState:
08:47:21,696 WARN JDBCExceptionReporter:28 - [Microsoft][SQLServer 2000 Driver
for JDBC][SQLServer]已将语言设置改为 简体中文。

_________________
I am the creatxr of world.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 11, 2004 9:05 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
What the hell is all this {foo} stuff?? That is not HQL. Please read the Hibernate documentation.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 12, 2004 6:30 am 
Regular
Regular

Joined: Sat Apr 10, 2004 8:39 pm
Posts: 84
queries with "select new" now cacheable
---------- it can't using in more than one table?

====================================

i want do :
Query query = ss.createQuery("select new SectionalFields(a.x,b.y) from A a, B b");

============================

problem 1:

For using Class "SectionalFields", we must write codes "<import class="SectionalFields"/>" in *.hbm.xml

if i only do "select new SectionalField2(a.x) from A a", it has no problem.
but i want select fields from more than 1 table.
so i write "<import class="SectionalFields"/>" in A.hbm.xml and B.hbm.xml

error: duplicable import class SectionalFields

==========

problem 2:

because of problem 1, i only write "<import class="SectionalFields"/>"
in A.hbm.xml or B.hbm.xml
but it can's pass!!!!

==================================
what's the problem? for queries with "select new" can't using in more than 1 table? Or i've done some wrong??

_________________
I am the creatxr of world.


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