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