[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] Internal ClassCastException in 2.1: @OrderBy not respecting user collection type
|
It doesn't make sense to have an ordered HashSet. If you want
something to be ordered, it has to be a List. Eclipselink can't order
your HashSet.
./tch
On Mon, Aug 30, 2010 at 3:27 PM, Laird Nelson <ljnelson@xxxxxxxxx> wrote:
> I have an entity with a @OneToMany field. It's mapped like this:
>
> @OneToMany(cascade = { CascadeType.PERSIST, CascadeType.REMOVE },
> mappedBy = "foo", targetEntity = BarEntity.class)
> @OrderBy
> private Collection<Bar> stuff;
>
> I discovered that if I initialize this myself like this in, say, the
> constructor:
>
> this.stuff = new LinkedHashSet<Bar>();
>
> ...I get a class cast exception during persist that says:
>
> java.lang.ClassCastException: java.util.LinkedHashSet cannot be cast
> to java.util.List
> at org.eclipse.persistence.internal.queries.OrderedListContainerPolicy.iteratorFor(OrderedListContainerPolicy.java:429)
> at org.eclipse.persistence.mappings.CollectionMapping.cascadeRegisterNewIfRequired(CollectionMapping.java:369)
> at org.eclipse.persistence.internal.descriptors.ObjectBuilder.cascadeRegisterNewForCreate(ObjectBuilder.java:1684)
> at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:4212)
> at org.eclipse.persistence.internal.jpa.EntityManagerImpl.persist(EntityManagerImpl.java:384)
>
> Is there some section of the JPA 2.0 specification that says what
> collection types are permitted? Or that the kind of Collection
> annotated by @OrderBy must be a List? Is this pilot error or a bug?
>
> Thanks,
> Laird
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>