-->
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: Help with order-by sql generation (possible parser bug)
PostPosted: Fri Jan 21, 2005 7:12 pm 
Senior
Senior

Joined: Sun Oct 26, 2003 5:05 am
Posts: 139
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
Latest of homepage, 2.1.7 I believe

Mapping documents:
Code:
   <class
      name="com.borderconnect.domain.shipment.sequence.Sequence"
      table="shipment_sequence"
   >
      <id name="id" column="id" type="long" unsaved-value="0">
         <generator class="sequence">
            <param name="sequence">shipment_sequence_id_seq</param>
         </generator>
      </id>
      <property name="dateCreated" column="date_created"  />
      <many-to-one name="creator" column="creator_id"
         class="com.borderconnect.domain.Person" />
      <component name="shipmentType" class="com.borderconnect.domain.shipment.ShipmentType">
         <property name="name" column="shipment_type" />
      </component>
      <bag name="shipments" table="shipment" lazy="true" inverse="true"
         cascade="all" order-by="to_number(cargoControlNumber.sequence,'999999999999999999999') asc"
      >
         <key column="shipment_sequence_id"/>
         <one-to-many class="com.borderconnect.domain.shipment.Shipment"/>
      </bag>
   </class>


Name and version of the database you are using:
Postgres 8

The generated SQL (show_sql=true):
Code:
[17:53:00,875]DEBUG SQL:229 - select sequence0_.id as id0_, shipments1_.id as id1_, sequence0_.date_created as date_cre2_0_, sequence0_.creator_id as creator_id0_, sequence0_.shipment_type as shipment4_0_, shipments1_.carrier_code_id as carrier_2_1_, shipments1_.sequence as sequence1_, shipments1_.pars_position as pars_pos4_1_, shipments1_.transaction_number as transact5_1_, shipments1_.service_option_id as service_6_1_, shipments1_.release_office_id as release_7_1_, shipments1_.sub_location_id as sub_loca8_1_, shipments1_.container_number as containe9_1_, shipments1_.current_status_id as current10_1_, shipments1_.driver_id as driver_id1_, shipments1_.shipment_sequence_id as shipmen12_1_, shipments1_.is_purged as is_purged1_, shipments1_.shipment_sequence_id as shipmen12___, shipments1_.id as id__ from shipment_sequence sequence0_ left outer join shipment shipments1_ on sequence0_.id=shipments1_.shipment_sequence_id where (sequence0_.id=? ) order by shipments1_.to_number(cargoControlNumber.sequence, shipments1_.'999999999999999999999') asc


As you can see in the mapping, I'm doing "order-by="to_number(cargoControlNumber.sequence,'999999999999999999999') asc" for the shipments bag. This order by works in postgres just fine. However, Hibernate doesn't understand the use of the function/parameters and generates the following SQL problem:

Code:
order by shipments1_.to_number(cargoControlNumber.sequence, shipments1_.'999999999999999999999') asc


Is there any way to tell Hibernate to generate the proper SQL? Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 22, 2005 10:29 am 
Senior
Senior

Joined: Sun Oct 26, 2003 5:05 am
Posts: 139
I tried to search for this but I can't find anything in the forums. This is the closest thing to it, and it's a year old:

http://forum.hibernate.org/viewtopic.ph ... y+function

But this person was having a database issue instead of a hibernate issue. In my case, Hibernate is just parsing my order-by attribute incorrectly and is therefore generating bad SQL. I know I tried to do cargoControlNumber.sequence (because I was unsure if it generted an HQL query before SQL using a double-pass), but the problem is still the same.

Having to query the list of shipments separately kind of sucks since they are integral to the model. There is a lot of behaviour on Sequence.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 22, 2005 10:44 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
The parser for the order-bys is currently pretty simple and what you want to do just does not work. Patches are welcome :) Look at org.hibernate.sql.Template where it is done.


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.