Hi there,
I am trying to use @Any mapping.
I downloaded the latest GA of hibernate core and annotations.
I've added the @Any mapping manually to the annotations module using instructions from
here.
My mappings were implemented with hbm so far - and eveything worked fine. Now that I've changed the any mapping from xml format
Code:
<any>
to annotations
Code:
@Any
the ddl created is corrupted.
Instead of 2 columns representing the Type and Id, I get one unexplained column...
Here are the details of the code :
3 classes are involved
class 1 :
Authorized UserHas a field of type
Code:
Object
that can be either type
Code:
Portlet
or type
Code:
Module
.
The mapping was written following an example from the above URL. here is the code :
Code:
@Any(metaColumn = @Column(name = "PARENT_ENTITY_NAME"))
@AnyMetaDef(idType = "long", metaType = "string", name = "parent",
metaValues = {
@MetaValue(value = "models.Module", targetEntity = Module.class ),
@MetaValue(value = "models.Portlet", targetEntity = Portlet.class )
})
@Cascade(value = {CascadeType.SAVE_UPDATE})
@Index(name = "DSH_AUTH_USR_UX1")
@JoinColumn(name = "PARENT_ID")
As you can see there should be 2 columns :
"PARENT_ENTITY_NAME" which is the metaColumn (the discriminator) and "PARENT_ID" which is simply the ID of the object - which is the standard mapping for <any> relationship.
Classes 2 & 3 :
Module / Portlet , has a field
Code:
List<AuthorizedUser>
with mapping as follows :
Code:
@OneToMany(mappedBy = "parent")
Resulting DDL from hbm2ddl task :
In the sql script I get 1 column named
Code:
"parent"
(which is the field's name), and the column is of type
Code:
"varchar(255)"
(using sqlserver).
When the task reaches the @OneToMany mapping, it throws exception that the types mismatch - meaning the parent column is of type varchar when the FK for the mapping is the ID and is of type LONG.
Obviously it ignores the @Any mapping.
I don't understand how the facts connects - the hbm2ddl task should not be aware of the implementation for the mappings (hbm / annotations) but somehow it connects. So the question is - how do I get this to work ? [/code]