-->
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.  [ 8 posts ] 
Author Message
 Post subject: Association entities are not retrieved in the right order
PostPosted: Wed Feb 06, 2008 10:36 am 
Newbie

Joined: Wed Feb 06, 2008 10:06 am
Posts: 14
Hi there,
I'm working under Hibernate 3.1.3, in a Java 5 EE Application
I have an entity called REFERENCE and one called PASSAGE_POINT. A Reference has one or more PassagePoint. The PassagePoint for a given Reference are sorted according to the delayAfterDeparture (DELAY_AFTER_DEPARTURE) member in PassagePoint.

Here is my two mapping files.
Reference.hbm.xml:
Code:
<hibernate-mapping default-cascade="none">
    <class name="com.thalys.opalys.domain.ReferenceImpl" table="REFERENCE" dynamic-insert="false" dynamic-update="false">
        <id name="id" type="java.lang.Long" unsaved-value="null">
            <column name="ID" sql-type="BIGINT"/>
            <generator class="native">
            </generator>
        </id>
        <property name="startTime" >
            <column name="START_TIME" not-null="true" unique="false" sql-type="VARCHAR(255) BINARY"/>
            <type name="org.joda.time.contrib.hibernate.PersistentLocalTimeAsString">
            </type>
        </property>
        <property name="displayName" >
            <column name="DISPLAY_NAME" not-null="true" unique="false" sql-type="VARCHAR(255) BINARY"/>
            <type name="java.lang.String">
            </type>
        </property>
        <many-to-one name="axis" class="com.thalys.opalys.domain.AxisImpl" cascade="none" foreign-key="REFERENCE_AXIS_FKC" lazy="proxy" fetch="select">
            <column name="AXIS_FK" not-null="true" sql-type="BIGINT"/>
        </many-to-one>
        <set name="passagePoints" order-by="DELAY_AFTER_DEPARTURE" lazy="false" fetch="select" inverse="true" cascade="delete">
            <key foreign-key="PASSAGE_POINT_REFERENCE_FKC">
                <column name="REFERENCE_FK" sql-type="BIGINT"/>
            </key>
            <one-to-many class="com.thalys.opalys.domain.PassagePointImpl"/>
        </set>
        <set name="variantes" order-by="REFERENCE_FK" lazy="false" fetch="select" inverse="true" cascade="delete">
            <key foreign-key="VARIANTE_REFERENCE_FKC">
                <column name="REFERENCE_FK" sql-type="BIGINT"/>
            </key>
            <one-to-many class="com.thalys.opalys.domain.VarianteImpl"/>
        </set>
    </class>
</hibernate-mapping>


PassagePoint.hbm.xml:
Code:
<hibernate-mapping default-cascade="none">
    <class name="com.thalys.opalys.domain.PassagePointImpl" table="PASSAGE_POINT" dynamic-insert="false" dynamic-update="false">
        <id name="id" type="java.lang.Long" unsaved-value="null">
            <column name="ID" sql-type="BIGINT"/>
            <generator class="native">
            </generator>
        </id>
        <property name="delayAfterDeparture" >
            <column name="DELAY_AFTER_DEPARTURE" not-null="true" unique="false" sql-type="INTEGER"/>
            <type name="int">
            </type>
        </property>
        <property name="distanceOnClassicLines" >
            <column name="DISTANCE_ON_CLASSIC_LINES" not-null="true" unique="false" sql-type="DOUBLE"/>
            <type name="double">
            </type>
        </property>
        <property name="distanceOnHighSpeedLines" >
            <column name="DISTANCE_ON_HIGH_SPEED_LINES" not-null="true" unique="false" sql-type="DOUBLE"/>
            <type name="double">
            </type>
        </property>
        <many-to-one name="previousPoint" class="com.thalys.opalys.domain.PassagePointImpl" foreign-key="PASSAGE_POINT_PREVIOUS_POINT_C" cascade="delete" lazy="proxy" fetch="select">
            <column name="PREVIOUS_POINT_FK" not-null="false" sql-type="BIGINT" unique="true"/>
        </many-to-one>
        <one-to-one name="nextPoint" class="com.thalys.opalys.domain.PassagePointImpl"  property-ref="previousPoint" cascade="none" lazy="proxy" fetch="select"/>
        <many-to-one name="reference" class="com.thalys.opalys.domain.ReferenceImpl" cascade="none" foreign-key="PASSAGE_POINT_REFERENCE_FKC" lazy="proxy" fetch="select">
            <column name="REFERENCE_FK" not-null="true" sql-type="BIGINT"/>
        </many-to-one>
        <many-to-one name="point" class="com.thalys.opalys.domain.ParticularPointImpl" cascade="none" foreign-key="PASSAGE_POINT_POINT_FKC" lazy="proxy" fetch="select">
            <column name="POINT_FK" not-null="true" sql-type="BIGINT"/>
        </many-to-one>
    </class>
</hibernate-mapping>


This is an AndroMDA auto-generated code. And this usually works fine, passage point were retrieved in the right order. But i might have changed something, and now in some cases its not working anymore. They are retrieved in the opposite order....

This is a weird thing and i can't understand it.

Thanks in advance...
[/code]


Top
 Profile  
 
 Post subject: Re: Association entities are not retrieved in the right orde
PostPosted: Wed Feb 06, 2008 11:12 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
What if you force the order by asc/desc?



Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 06, 2008 11:40 am 
Newbie

Joined: Wed Feb 06, 2008 10:06 am
Posts: 14
Ok, point is, this hbm files are generated by AndroMDA code generator.
So i dont have any power on this.
BUT in the UML file where AndroMDA gets his info (UML file i build myself), i managed to precise ASC order.
But it still doesnt work.....

I will enable DEBUG on org.hibernate to see precisely whats going on and i'll let you updated on this.
Thanks :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 06, 2008 11:43 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
What is the Java instance for the set? Is it a set that can keep the order?


Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 07, 2008 6:36 am 
Newbie

Joined: Wed Feb 06, 2008 10:06 am
Posts: 14
It is declared as a java.util.Collection.
On RunTime it is a org.hibernate.collection.PersistentSet.

But anyway in my hbm it is supposed to be sorted. That is why i dnt understand. When i retrieve one Reference already created before my transaction, its ok, items are in the right order.
If i retrieve a Reference i just created, although i created it with the passage points in the right order (verified in debug mode), and although they are stored in the right order, i get them in the opposite order. But only in this very precise case where i just created the Reference before.

I'm trying to understand, but i can't... :(


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 07, 2008 12:36 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
nicdo77 wrote:
If i retrieve a Reference i just created, although i created it with the passage points in the right order (verified in debug mode), and although they are stored in the right order, i get them in the opposite order.(



That might be the point. tell me, do you use a java.util.LinkedHashSet when you create a reference? Can you verify if the order is right in the database and it is only a problem of retrieving data?


Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 11, 2008 12:24 pm 
Newbie

Joined: Wed Feb 06, 2008 10:06 am
Posts: 14
When i create a reference, i use for the passage points a HashSet, have a look at this line of code i found in my AndroMDA-generated file...

Code:
private java.util.Collection<com.thalys.opalys.domain.PassagePoint> passagePoints = new java.util.HashSet<com.thalys.opalys.domain.PassagePoint>();


The order is right in the database, it is a problem of retrieving data...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 11, 2008 12:26 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
Replace it with LinkedHashSet and see if that makes a difference. HashSet is not ordered. However, I am not sure if that will solve the problem.


Farzad-


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