-->
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 custom Order criterion using CriteriaQueryTranslator
PostPosted: Tue Dec 06, 2005 10:48 pm 
Newbie

Joined: Tue Dec 06, 2005 4:10 am
Posts: 3
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0.5

Mapping documents:
<?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="com.eclasia.wos.domain.Product" table="ELOGFP.STPROD1P">
<id name="code" column="BAPROD">
<generator class="assigned"/>
</id>
<property name="name" column="BANAME"/>
<property name="category" column="BACATG"/>
<property name="country" column="BACTRY"/>
</class>
</hibernate-mapping>




Name and version of the database you are using: AS400 DB2 V5R1

The generated SQL (show_sql=true):
Hibernate: select this_.BAPROD as BAPROD0_, this_.BANAME as BANAME2_0_, this_.BACATG as BACATG2_0_, this_.BACTRY as BACTRY2_0_ from ELOGFP.STPROD1P this_ where this_.BAPDST=? and this_.BASUPP=? order by this_.BAPROD asc fetch first 50 rows only



I would like to create a new MyOrder class, override the class

org.hibernate.criterion.Order

such that the MyOrder.toSqlString() will return the column alias "order by BAPROD0_ asc" instead of "order by this_.BAPROD asc" which contains the table alias followed by the column name.

public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
StringBuffer fragment = new StringBuffer();
.....
return fragment.toString();
}

How can I do this with the CriteriaQuery / CriteriaQueryTranslator??

Your help is greatly appreciated.


Top
 Profile  
 
 Post subject: SQL
PostPosted: Tue Dec 06, 2005 11:10 pm 
Newbie

Joined: Tue Dec 06, 2005 4:10 am
Posts: 3
In other words, I want to generate

select this_.BAPROD as BAPROD0_, this_.BANAME as BANAME2_0_, this_.BACATG as BACATG2_0_, this_.BACTRY as BACTRY2_0_ from ELOGFP.STPROD1P this_ where this_.BAPDST=? and this_.BASUPP=? order by BAPROD0_ asc fetch first 50 rows only

instead of:

select this_.BAPROD as BAPROD0_, this_.BANAME as BANAME2_0_, this_.BACATG as BACATG2_0_, this_.BACTRY as BACTRY2_0_ from ELOGFP.STPROD1P this_ where this_.BAPDST=? and this_.BASUPP=? order by this_.BAPROD asc fetch first 50 rows only


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.