-->
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.  [ 4 posts ] 
Author Message
 Post subject: HELP with sorted/ordered Set please
PostPosted: Thu Feb 15, 2007 12:18 pm 
Beginner
Beginner

Joined: Fri Oct 06, 2006 7:11 am
Posts: 32
Hi,

I am well through a project and have now had to change my code to allow for sorted collections. I have a unidirectional mapping in my parent class
(CertificateStatementTitle) that contains one or more of CertificateStatement. This has worked fine before but now I need to have this sorted I'm getting problems.

I'd like to sort the CertificateStatements on a field CERTIFICATE_CODE within that class but its not working. I've tried to add an <index column="CERTIFICATE_CODE" type"string"/> to the mapping file as I've shown below but it seems that I can't use this with a set.

I have a lot of data alread in my database and am reluctant to have to redesign too much and loose this data.

Is there a quick way I can get this set ordered or sorted >

Please help as I'm a bit stuck on this. I'm not using the new annotations and don't want to have to change everything at this stage of my project.

thanks in advance


Hibernate version: 3.1

Mapping documents:
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="ie.gov.agriculture.dpcs.cert.CertificateStatementTitle" lazy="false" table="CERT_STATEMENT_TITLE">
       <id name="certificateStatementTitleId" column="CERT_STATEMENT_TITLE_ID" unsaved-value="0" type="long">
           <generator class="sequence">
              <param name="sequence">CERT_STMT_TITLE_ID_SEQ</param>
           </generator>
      </id>
         <set name="certificateStatements"
             table="CERT_STMT_TITLE_STMT_LINKS"
             cascade="all"
             order-by="STATEMENT_CODE asc">
          <key column="CERT_STATEMENT_TITLE_ID"/>
            <index column="CERTIFICATE_CODE" type"string"/>
          <many-to-many column="CERTIFICATE_STMT_ID"
                        class="ie.gov.agriculture.dpcs.cert.CertificateStatement"/>
      </set>

    </class>
</hibernate-mapping>


public class CertificateStatementTitle  implements Serializable{

    private Long certificateStatementTitleId = Long.valueOf("0");
    private Set certificateStatements = new LinkedHashSet();

........




Name and version of the database you are using:Oracle 9


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 15, 2007 12:40 pm 
Beginner
Beginner

Joined: Fri Oct 06, 2006 7:11 am
Posts: 32
As an update, this is the generated SQL, the order clause is basically on the wrong table, is there a way I can get this to order on the correct table ?

Code:
    select
        certificat0_.CERT_STATEMENT_TITLE_ID as CERT1_1_,
        certificat0_.CERTIFICATE_STMT_ID as CERTIFIC2_1_,
        certificat1_.CERTIFICATE_STMT_ID as CERTIFIC1_4_0_,
        certificat1_.STATEMENT_CODE as STATEMENT2_4_0_
    from
        dev_test.CERT_STMT_TITLE_STMT_LINKS certificat0_,
        dev_test.CERT_STATEMENT certificat1_
    where
        certificat0_.CERTIFICATE_STMT_ID=certificat1_.CERTIFICATE_STMT_ID(+)
        and certificat0_.CERT_STATEMENT_TITLE_ID=?
    order by
        certificat0_.STATEMENT_CODE asc


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 16, 2007 5:49 am 
Beginner
Beginner

Joined: Fri Oct 06, 2006 7:11 am
Posts: 32
Can no-one help me with this ???


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 16, 2007 6:44 am 
Beginner
Beginner

Joined: Fri Oct 06, 2006 7:11 am
Posts: 32
Guess I should have looked into the documentation a bit more.

I managed to solve the problem by writing my own class that implements the Comparable interface and using that as the sort attribute in the hbm file.


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