You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Leszek Gawron <lg...@mobilebox.pl> on 2005/09/06 09:41:13 UTC
OT: O/R collection mapping [was: SQLTransformer]
Antonio Gallardo wrote:
> Using "orderby" attribute -
> http://db.apache.org/ojb/docu/guides/repository.html#collection-descriptor
> There is no need of an extra field.
you can do it same way in hibernate. see:
http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#collections-sorted
<quote>
If you want the database itself to order the collection elements use
the order-by attribute of set, bag or map mappings. This solution is
only available under JDK 1.4 or higher (it is implemented using
LinkedHashSet or LinkedHashMap). This performs the ordering in the SQL
query, not in memory.
<set name="aliases" table="person_aliases" order-by="lower(name) asc">
<key column="person"/>
<element column="name" type="string"/>
</set>
</quote>
Moreover you can use a TreeSet that allows you to implement sorting not
available to SQL (via use of Comparable interface).
Still your bean needs to have properties that define the order.
Let me give you an example that advocates the use of index field.
- a Person class (firstName, lastName, age)
- Marathon class:
- name
- place
- date
- thoseWhoFinishedTheRace collection which is a sorted list of those
Persons who managed to get to the finish line. The list is sorted in an
order of finishing so thoseWhoFinishedTheRace().get( 0 ) is the winner.
In this example the collection is not _sorted_ - it is _ordered_ with
information not available to Person bean. The use of index field is
mandatory - it's not bad database design.
> In my case, I met the Unsupported Operation Exception in jxpath using
> @direction="save" not while loading a not with a repeater, but using a
> cform multivalue field.
Could you give me some test case? I tried to stay out of MultiValueField
binding as it always rewrites the whole collection which causes multiple
deletes/inserts.
--
Leszek Gawron lgawron@mobilebox.pl
IT Manager MobileBox sp. z o.o.
+48 (61) 855 06 67 http://www.mobilebox.pl
mobile: +48 (501) 720 812 fax: +48 (61) 853 29 65
Re: OT: O/R collection mapping [was: SQLTransformer]
Posted by Leszek Gawron <lg...@mobilebox.pl>.
Antonio Gallardo wrote:
> Not sure is there can be a usecase where you will not need to store a
> value in the DB. But, let assume the special usecase exists, then the
> additional index should be "optional" and not obligatory as is now in
> hibernate. ;-)
It is obligatory for mapping a List. You can map your collection as Set
and do not need index then.
> I also noted [0]: "The index of an array or list is always of type
> integer."
Again: this is the context of List mapping.
>
> Again, this is a non-sense: Obligatory index + obligatory index type!
>
> Of course, this does not cover cases where the user prefer to use
> another index type, for example a string or a char or whatever other
> type the user want to use. This is another reason to choose Apache OJB
> [1]. The worse is that instead of offer a solution in hibernate 3, they
> offer just "a cool justification" why this non-sense [0]. I really
> wonder how is people using hibernate after all. The only answer I found
> is "they must have an excelent marketing engine a la
> ${readerPreferedCorporate.getName()}". ;-)
There is completely no problem to use another index type but this is not
List then. How would you like to index your list with non integers when
java.util.List is indexed with integers only?
For your usecase you should map your collection as java.util.Map.
I am doing hibernate almost 2 years now and haven't found a single
usecase where I would have to adjust my database schema just because I'm
using hibernate.
I am sure both OJB and Hibernate would do just fine for 99% cases. We
could bring up a lot of arguments and the other side could probably
easily turn them down. Let's maybe do it like this: You create a
database schema which you map to OJB and I will provide hibernate
mappings. Then I will challenge you :) We can put results on wiki so our
users see that both O/R techniques are feasible for single database
schema. WDYT?
--
Leszek Gawron lgawron@mobilebox.pl
IT Manager MobileBox sp. z o.o.
+48 (61) 855 06 67 http://www.mobilebox.pl
mobile: +48 (501) 720 812 fax: +48 (61) 853 29 65
Re: OT: O/R collection mapping [was: SQLTransformer]
Posted by Antonio Gallardo <ag...@agssa.net>.
Leszek Gawron wrote:
> Vadim Gritsenko wrote:
>
>> Leszek Gawron wrote:
>>
>>> - Marathon class:
>>> - name
>>> - place
>>> - date
>>> - thoseWhoFinishedTheRace collection which is a sorted list of
>>> those Persons who managed to get to the finish line. The list is
>>> sorted in an order of finishing so thoseWhoFinishedTheRace().get( 0
>>> ) is the winner.
>>>
>>> In this example the collection is not _sorted_ - it is _ordered_
>>> with information not available to Person bean. The use of index
>>> field is mandatory - it's not bad database design.
>>
>>
>> It is bad - good design will have 'finished' timestamp ;-P
>
> LOL. Still there are several usecases when you do not have a field to
> sort on like "a list of shirts I like best starting from the most
> favourite one". :)
>
Not sure is there can be a usecase where you will not need to store a
value in the DB. But, let assume the special usecase exists, then the
additional index should be "optional" and not obligatory as is now in
hibernate. ;-)
I also noted [0]: "The index of an array or list is always of type integer."
Again, this is a non-sense: Obligatory index + obligatory index type!
Of course, this does not cover cases where the user prefer to use
another index type, for example a string or a char or whatever other
type the user want to use. This is another reason to choose Apache OJB
[1]. The worse is that instead of offer a solution in hibernate 3, they
offer just "a cool justification" why this non-sense [0]. I really
wonder how is people using hibernate after all. The only answer I found
is "they must have an excelent marketing engine a la
${readerPreferedCorporate.getName()}". ;-)
IMO, a good O/R mapping tool should not force us to "hack" our database
or our code. ;-)
Best Regards,
Antonio Gallardo.
[0] http://www.hibernate.org/hib_docs/reference/en/html/collections.html
[1] http://db.apache.org/ojb/
Re: OT: O/R collection mapping [was: SQLTransformer]
Posted by Leszek Gawron <lg...@mobilebox.pl>.
Vadim Gritsenko wrote:
> Leszek Gawron wrote:
>
>> - Marathon class:
>> - name
>> - place
>> - date
>> - thoseWhoFinishedTheRace collection which is a sorted list of those
>> Persons who managed to get to the finish line. The list is sorted in
>> an order of finishing so thoseWhoFinishedTheRace().get( 0 ) is the
>> winner.
>>
>> In this example the collection is not _sorted_ - it is _ordered_ with
>> information not available to Person bean. The use of index field is
>> mandatory - it's not bad database design.
>
>
> It is bad - good design will have 'finished' timestamp ;-P
LOL. Still there are several usecases when you do not have a field to
sort on like "a list of shirts I like best starting from the most
favourite one". :)
--
Leszek Gawron lgawron@mobilebox.pl
IT Manager MobileBox sp. z o.o.
+48 (61) 855 06 67 http://www.mobilebox.pl
mobile: +48 (501) 720 812 fax: +48 (61) 853 29 65
Re: OT: O/R collection mapping [was: SQLTransformer]
Posted by Vadim Gritsenko <va...@reverycodes.com>.
Leszek Gawron wrote:
> - Marathon class:
> - name
> - place
> - date
> - thoseWhoFinishedTheRace collection which is a sorted list of those
> Persons who managed to get to the finish line. The list is sorted in an
> order of finishing so thoseWhoFinishedTheRace().get( 0 ) is the winner.
>
> In this example the collection is not _sorted_ - it is _ordered_ with
> information not available to Person bean. The use of index field is
> mandatory - it's not bad database design.
It is bad - good design will have 'finished' timestamp ;-P
Vadim