-->
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: pattern for mapping a default entity?
PostPosted: Tue Dec 30, 2008 10:46 am 
Newbie

Joined: Mon Jan 08, 2007 1:17 pm
Posts: 2
Is there a sleek way to map a default object in Hibernate?

For example, in this class, a Foo should always be able to return a Bar, whether it's custom defined for the Foo, or it comes from a default value that's stored in the database somewhere. Users of Foo should be able to set a custom Bar object in it, but they don't need write access to Bar - hence the reduced visibility. :

Code:
public Class Foo {
    public Bar Bar {
        get {
            return CustomBar ?? DefaultBar;
        }
    }

    public Bar CustomBar { get; set; }
    protected Bar DefaultBar { get; private set; }
}


The thing I'm wondering about is how to hibernate map that DefaultFoo property. All the Bar classes should be able to get to that single DefaultFoo object. The only way I know how to do this in Hibernate is with a one-to-many mapping in Foo. (Foo containing one to many Bars)...this seems a little kludgy though, since there's always at most one Bar. Is there a better pattern for this type of behavior? TIA.


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.