These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: hbm2ddl does not support @Any mapping as far as I can see
PostPosted: Sun Dec 09, 2007 4:22 am 
Newbie

Joined: Sun Dec 09, 2007 3:45 am
Posts: 2
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 User
Has 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]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.