max wrote:
well - the advantage of the hibernate metamodel is that it is used by both the hbm and annotation binder and thus includes exactly the information needed to do it automatically...
Of course. I assume the hbm model covers the entire metamodel, but from what I've seen the annotation binder doesn't yet do that. So the map from ejb3 annotations to the metamodel is not (in all cases) invertible.
Since (if) the hbm model covers the entire metamodel, then it also includes exactly the information needed.
When I was initially looking at Hibernate Annotations, I went through the code a bit to try and fix my problems. By nature of it's design it needs a lot of code like:
Code:
if (annotatedClass.isAnnotationPresent(javax.persistence.Table.class) )
i.e. for each annotation / part of the metamodel, the binding has to be implemented by hand. This code is not reusable to implement the reverse mapping. If the reverse mapping was implemented it would have to be maintained separately.
My approach was to annotate my annotations, e.g.
Code:
@XmlElement(name="class")
@AddClassNameAsAttribute(name="name")
public @interface H8Class
can generate
Code:
<class name="my.EntityClass">
from
Code:
@H8Class class EntityClass
and
Code:
@XmlAttribute @DefaultFromGenericType(-1) String[] type() default {};
means that
Code:
@H8Set(... ) Set<String> stuff;
can generate
Code:
type="java.lang.String"
and adding new elements / attributes involves no coding.
Annotations and their properties map directly onto elements and attributes. So implementing the reverse map would be reasonably doable - and once implemented easy to maintain.
Maybe there is some analog to my approach whereby the hibernate metamodel could be annotated with the mapping needed by the hbm or annotation binder. If that was possible maybe the reverse mapping would work out cheaper to implement?
cheers,
eoin.