-->
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: Question: One class, multiple tables
PostPosted: Sat Aug 26, 2006 7:13 pm 
Newbie

Joined: Sat Aug 26, 2006 6:54 pm
Posts: 1
Hibernate version: 3

Summary: How do I specify the table name for a hibernate persisted object at runtime? And how can I ensure instances of the same Class can reference different tables without interfering with each other?

----------------------------------------------

I'm trying to convert a partially-complete application to Hibernate, and I'm not having any luck finding info about how to have a class that can have its table specified at runtime.

The class in question implements hierarchical trees in the database. Each "named tree" has its own table, named "tree_{treename}". Each tree table has identical column names.

The code as it stands works like (edited for simplicity):

Tree tree = TreeManager.instance().getTreeRef("table-name");
Node root = tree.getRoot();
List<Node> toplevel = root.getChildren();
... etc ...

Each 'Node' has a reference to the 'Tree' object, which contains the name of the database table that was specified in the .getTreeRef() method call. The DAO uses that table name in all the SQL calls.

------------------------------

How would I go about converting this to Hibernate? I've googled, and can't find my way around these stumbling blocks:

(1) Having Hibernate use a dynamically chosen table.

(2) Not having hibernate explode when Nodes n1 and n2 have the same ID but different tables.

(3) Doing two-step commits (I'm using materialized paths for the tree functionality, so on creating a new node, I need to save it to get its ID value, then change its path to (parent + id) and save that field.)

(4) Those things I haven't thought of yet ;)

Any help is appreciated!

Cheers,
-Darren


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.