-->
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: Custom type or persister - or other approach?
PostPosted: Thu Jan 03, 2013 11:12 am 
Newbie

Joined: Thu Jun 14, 2012 9:47 am
Posts: 1
Hi all,

I'm looking at using Hibernate to implement a scenario where I'm aggressively caching part of the object graph. I've been going through the documentation on things like custom types, but I'd very much appreciate any suggestions that you might have for how to best achieve my goal.

My domain model basically looks like

Code:
class A {
    String id;
    B b;
}
class B {
    String id;
}


with the obvious underlying datamodel where the A table contains a foreign key referring to the id column of the B table; IOW a many-to-one relation between A and B.

I would now like to preload all of the B instances into a map from B-id to B-instance, so when I'm loading an A instance from the database I can resolve the B reference by just looking up the B instance in the map. Corresponding to this, when I'm updating or creating an A instance I would like to just retrieve the id value of the associated B instance and store that in the underlying column without verifying the existence of the B key in the database.

Later on I will also need this to work going in the other direction where B has a collection of A's and the A instances are retrieved from a map.

My immediate thought was to implement a custom type for this purpose, but as that's intended for value types only and not entities I'm not sure if it will work, especially when it comes to collection mapping. Is it necessary to create a custom persister instead, and would that even be possible given the requirement that the initial preload from the database should still work?

Best regards & thanks,
Mikkel Lauritsen


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.