-->
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.  [ 2 posts ] 
Author Message
 Post subject: How to restrict on a primitive array type using a criteria?
PostPosted: Sun Jun 21, 2009 11:43 am 
Newbie

Joined: Sun Jun 21, 2009 11:21 am
Posts: 2
Hi,

This has been driving me crazy for hours so any help would be much appreciated. I have the following class:

Code:
public class Song
{
    private String id;
    private String[] artistNames;
    ...
}


with the following mapping:

Code:
<class name="com.test.Song" table="SONG">
    <id name="id" column="id">
        <generator class="assigned"/>
    </id>
    <array name="artistNames" table="SONG_ARTIST_NAMES" cascade="all">
        <key column="song_id"/>
        <index column="index"/>
        <element column="value" type="string"/>
    </array>
</class>


and I want to retrieve Songs which contain a specific artist name. I can do this with HQL using:

Code:
from Song where ? in elements(artistNames)


but I can't get it to work using Criterias.

I've tried various combinations of restrictions (like, IN and EQ) and joins but it always fails with an error. The errors are different depending on the type of Criteria I use but include "collection was not an association", "no value specified for parameter 1", and others.

The first error is noted in the advanced problems document where it says:

"Hibernate currently does not support joining a collection of components or other value types with Criteria."

Does this mean that Hibernate Criteria doesn't support querying collection properties of primitive types? Because that seems like a horrible limitation for such a basic functional requirement so I'm hoping my interpretation is wrong...

If not, how can I query the primitve collection in the example above using HIbernate's Criteria APIs?

Thanks in advance!


Top
 Profile  
 
 Post subject: Re: How to restrict on a primitive array type using a criteria?
PostPosted: Thu Jun 25, 2009 2:01 am 
Newbie

Joined: Sun Jun 21, 2009 11:21 am
Posts: 2
So nobody knows the answer to this?

If anyone else is having the same issue I've worked around it by converting my basic type arrays to Object arrays and creating an object that just represents the basic type, e.g.

Code:
public class Song
{
    private String id;
    private Artist[] artists;
    ...
}

public class Artist
{
    private String id;
    private String artistName;
    ...
}


It's more extendable and arguably more appropriate in the example above but a bit convoluted if you only ever need an array of basic types. Nevertheless it works and as far as I can tell is the only way to query arrays with Criteria.


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