-->
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.  [ 5 posts ] 
Author Message
 Post subject: Unique Column names mapping a deep value type hierarchy
PostPosted: Wed Feb 25, 2009 3:42 am 
Newbie

Joined: Wed Feb 25, 2009 3:17 am
Posts: 5
Location: Germany
Hello,

I have a problem mapping a given (=fixed) deep class hierarchy with value type inclusion. Here is a simplified version of the problem:

Code:
@Entity class A
{
    @Id String key;
    B b;
    C c;
}

@Embeddable class B
{
    String bla;
    D d;
}

@Embeddable class C
{
    String bli;
    D d;
}

@Embeddable class D
{
    String blubber;
}


The generated table for A (annotated as shown above) would have the columns: key, bla, bli, blubber

However, for a correct mapping it would need 2 blubber columns (one for class B and one for class C content).

Do you have any idea how to annotate the D.blubber member so the resulting DB table gets 2 blubber entries (without making class D an entity type)?

Thank you,
Robert[quote][/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2009 5:14 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
You can use AttributeOverride:
Code:
@Embedded
    @AttributeOverrides( {
            @AttributeOverride(name="d.blubber", column = @Column(name="c_d_blubber") )
    } )
    C c;


The example in the annotation guide also uses embedded components in embeddables, where the attributes get overridden.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2009 5:36 am 
Newbie

Joined: Wed Feb 25, 2009 3:17 am
Posts: 5
Location: Germany
Thank you, mmerder! Your description would solve the problem I described; however I left out some details from my real scenario which make the topic more tricky:

The classes B, C and D are generated automatically (from a WSDL file) and are processed one-by-one by regular expressions to add the persistence annotations. So class A doesn't know anything about the content of class B or C and thus doesn't know about class D..

A solution would be to annotate class A that any column name of any attribute of class B should get a preceding 'A_' - but I don't know if this is possible at all (or how to annotate this)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2009 5:48 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Quote:
A solution would be to annotate class A that any column name of any attribute of class B should get a preceding 'A_' - but I don't know if this is possible at all (or how to annotate this)


You can configure hibernate to use a save naming strategy, so that it allways puts the attribute name before embedded attributes.
Set property "hibernate.ejb.naming_strategy" to "org.hibernate.cfg.DefaultComponentSafeNamingStrategy" in your hibernate.cfg.xml or persistence.xml (if using JPA).

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2009 6:09 am 
Newbie

Joined: Wed Feb 25, 2009 3:17 am
Posts: 5
Location: Germany
Great!! Problem solved, thank you very much, mmerder!

best regards, Robert


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

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.