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

Edward Costello (JIRA) noreply at atlassian.com
Thu Nov 30 15:06:04 EST 2006


    [ http://opensource.atlassian.com/projects/hibernate/browse/ANN-494?page=comments#action_25514 ] 

Edward Costello commented on ANN-494:
-------------------------------------

In my example it was the @Embeddable class that had the unbound type. However that type was fixed by the @Embedded reference (actually a @CollectionOfElements).

I agree that this shouldn't work with @Entities. However @Embeddable types are defined by the context they're in. It's not possible to use them outside the context of another object.

With the classes below the type of Edition is not unresolved. Since the Edition is @Embeddable rather than @Entity, as long as the type of the @Embedded reference is not unbound it shouldn't really matter than the @Embeddable class is unbound.

@Embeddable
class Edition<T> {
   T name;
}

@Entity
class Book {
   @Embedded
   Edition<String> name;
}

The case I described in the ticket uses @CollectionOfElements rather than @Embedded but the basic concept is the same. In both cases the @Embedded or @CollectionOfElements is fully bound at compile time.

I don't know enough about the internals of hibernate to be sure but I suspect since we can override parts of the @Embeddable with @AttributeOverride you must keep a persister (or some such class) per @Embeddable reference rather than keeping one for the @Embeddable class. If this is the case it should be possible to resolve the type from the reference.

I'll attach a test case showing the exception with both an @Embedded reference and a @CollectionOfElements.

At the moment we're working around this by generating a subclass for each @Embedded reference with a different bound type.

> 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