[hibernate-dev] UserCollectionType mapping for Ceylon

Steve Ebersole steve at hibernate.org
Mon Nov 23 14:41:38 EST 2015


The annotation binder code does this checking.  Ultimately (unfortunately)
the binding code does need to understand whether to build a
o.h.mapping.Set, o.h.mapping.List, etc.  It makes the reasonable assumption
that the custom collection type (ceylon.collection.MutableSet) at least
implements one of the standard Java collection framework interfaces.  We
could certainly introduce a hint for cases like yours where that is not the
case (so long as you implement your own PersistentCollection as well that
should be enough).  Something like:

@org.hibernate.annotations.CollectionType(type = "hib.SetUserType",
nature=PluralAttributeNature.SET)

where `CollectionType.nature` is the
org.hibernate.boot.model.source.spi.PluralAttributeNature
enum:


public enum PluralAttributeNature {
BAG( Collection.class, false ),
ID_BAG( Collection.class, false ),
SET( Set.class, false ),
LIST( List.class, true ),
ARRAY( Object[].class, true ),
MAP( Map.class, true );
...
}

On Sun, Nov 22, 2015 at 4:38 AM Gavin King <gavin.king at gmail.com> wrote:

> Ah, OK, thanks for the link, Vlad, now I think I sorta maybe see why.
> With XML-based mappings, the semantic "kind" of collection is explicit
> (<list/> or <set/> or whatever) whereas with annotations that is
> determined by looking at the property type. The UserCollectionType
> doesn't actually have this information.
>
> So then I guess I'm going to need a bit of a deeper hack to make this work.
>
> On Sun, Nov 22, 2015 at 7:57 AM, Vlad Mihalcea <mihalcea.vlad at gmail.com>
> wrote:
> > I think that only the Java Collection types work with the JPA @OneToMany
> > associations, as it's described int his issue:
> >
> > https://hibernate.atlassian.net/browse/HHH-4417
> >
> > So, even when specifying a @CollectionType, the return type must be a
> > List/Set:
> >
> > @OneToMany(...)
> > @CollectionType( type="MyCustomListType" )
> > public List getOrders()
> >
> > Vlad
> >
> > On Sun, Nov 22, 2015 at 2:57 AM, Gavin King <gavin.king at gmail.com>
> wrote:
> >>
> >> On Sun, Nov 22, 2015 at 1:56 AM, Gavin King <gavin.king at gmail.com>
> wrote:
> >>
> >> > Of course this is surely the ideal way to handle this, but bear with
> >> > me for a sec because I would like to know why what I tried didn't
> >> > work.
> >>
> >> I mean "surely *not* the ideal way".
> >>
> >> --
> >> Gavin King
> >> gavin at ceylon-lang.org
> >> http://profiles.google.com/gavin.king
> >> http://ceylon-lang.org
> >> http://hibernate.org
> >> http://seamframework.org
> >> _______________________________________________
> >> hibernate-dev mailing list
> >> hibernate-dev at lists.jboss.org
> >> https://lists.jboss.org/mailman/listinfo/hibernate-dev
> >
> >
>
>
>
> --
> Gavin King
> gavin at ceylon-lang.org
> http://profiles.google.com/gavin.king
> http://ceylon-lang.org
> http://hibernate.org
> http://seamframework.org
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hibernate-dev
>


More information about the hibernate-dev mailing list