[hibernate-dev] UserCollectionType mapping for Ceylon

Gavin King gavin.king at gmail.com
Sat Nov 21 19:56:46 EST 2015


Hi Folks, so I'm making some first baby steps toward implementing
support for Ceylon's collections in Hibernate by trying to make use of
the existing UserCollectionType stuff.

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.

So I wrote my SetUserType to implement UserCollectionType, and then I
wrote the following Ceylon attribute:


    oneToMany { mappedBy="city"; }
    collectionType { type="hib.SetUserType"; }
    shared MutableSet<Person> people = HashSet<Person>();

Which is equivalent in the following Java:

    @javax.persistence.OneToMany(mappedBy = "city")
    @org.hibernate.annotations.CollectionType(type = "hib.SetUserType")
    @com.redhat.ceylon.compiler.java.metadata.Ignore
    private final ceylon.collection.MutableSet<Person> people;

But when I ran the code, I got this error:

Caused by: org.hibernate.AnnotationException: Illegal attempt to map a
non collection as a @OneToMany, @ManyToMany or @CollectionOfElements:
hib.City.people
at org.hibernate.cfg.annotations.CollectionBinder.getCollectionBinder(CollectionBinder.java:322)
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1874)
at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:904)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:731)
at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(AnnotationMetadataSourceProcessorImpl.java:245)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(MetadataBuildingProcess.java:222)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:265)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:770)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:797)
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:58)
... 32 more

Is @CollectionType supposed to work with @OneToMany?

Thanks,

Gavin


More information about the hibernate-dev mailing list