[hibernate-issues] [Hibernate-JIRA] Resolved: (ANN-494) Determine Referenced Entity For Embeddable types from the parameterised type

Paolo "Nusco" Perrotta (JIRA) noreply at atlassian.com
Thu Nov 30 10:28:04 EST 2006


     [ http://opensource.atlassian.com/projects/hibernate/browse/ANN-494?page=all ]
     
Paolo "Nusco" Perrotta resolved ANN-494:
----------------------------------------

    Resolution: Rejected

This is actually the expected behaviour. Revision 10893 contains a test that exposes it (and which I've since removed).

When we build the session factory, we do a static analysis to try and bind the generic types. When we do this we must err on the side of caution, because we don't know how the type is going to be used. Example:

- Book is an embeddable entity
- Edition<T> is an entity that references a T
- Reprint is an entity that references an Edition<Book>

At set-up, the system correctly complains because we have an unresolved type in Edition<T>. It might be possible that Edition<T> is only used as a field in Reprint, and that the type can actually be bound. But as far as the system knows, we might also try to persist an unbound Edition<T> by itself, which would be an error. The solution to this would dynamic type binding, but that has a number of trade-offs. So, we don't support that.

Please note that this is unrelated to @Embeddable, @OneToMany, collections, and so on. It's about allowing an entity (Edition in the example) to have "floating" types or not.


> Determine Referenced Entity For Embeddable types from the parameterised type
> ----------------------------------------------------------------------------
>
>          Key: ANN-494
>          URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-494
>      Project: Hibernate Annotations
>         Type: Improvement

>   Components: binder
>     Versions: 3.2.0.cr1
>     Reporter: Edward Costello
>     Assignee: Paolo "Nusco" Perrotta

>
>
> When a collection is mapped using @ManyToOne or @CollectionOfElements, the entity in the collection is derived from the parametrised type of the collection. e.g. there is no need to explicitly indicate the elements of the following collection are books.
> @ManyToOne
> Set<Book> books;
> It would be nice if the same kind of discovery could be applied to Embeddable types when contained in a CollectionOfElements. E.g. it would be nice if Hibernate could derive that the embedded Versioned references a Book in the example below
> @CollectionOfElements
> Set<Versioned<Book>>;
> @Embeddable
> class Versioned<T> {
>     T rightSide;
>     Date date;
> }
> Even if it wasn't derived, it would be good to be able to specify it. Currently the only way to make the above work is to create a subclass of Versioned that explicitly binds the type parameter to Book. Without this the below exception is thrown while building the session factory
> Exception in thread "main" java.lang.IllegalStateException: Property rightSide has an unbound type and no explicit target entity.
>    at org.hibernate.cfg.AnnotationBinder.addElementsOfAClass(AnnotationBinder.java:946)
>    at org.hibernate.cfg.AnnotationBinder.fillComponent(AnnotationBinder.java:1655)
>    at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1054)
>     at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:543)
>    at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:484)
>    at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:43)
>    at org.hibernate.cfg.annotations.CollectionBinder.bind(CollectionBinder.java:377)
>    at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1476)
>    at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:706)
>    at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:452)
>    at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:268)
>    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1210)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list