aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate: Dynamic Table Mapping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate: Dynamic Table Mapping" Watch "Hibernate: Dynamic Table Mapping" New topic
Author

Hibernate: Dynamic Table Mapping

Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
In the mapping file for a persistent class, the table attribute specifies the name of the database table to store data. With Hibernate, there are a few things that can be configured at runtime. Can the table name be configured in code rather than in the XML configuration file?

<class name="com.business.model.Record" table="user_record" node="record">

I want to persist user records to a table specific to the user, rather than a generic table for all records. For example, records for user #145 will be stored in dbo.145_user_record and records for user #456 will be stored in dbo.456_user_record.

Haven't figure out if this is possible with Hibernate. Any help is greatly appreciated.

Thanks.
Vivek Bakshi
Greenhorn

Joined: Apr 04, 2008
Posts: 4
Hi James,

I am also in the search for some similar solutions in hibernate...

Where does your #145 or blah.... values are coming... are these also dynamically generated or user defined?

Check for this thread below and see if this anything works for you... I have tried using the same, but no luck... All the best to you...

http://forum.hibernate.org/viewtopic.php?t=982727&highlight=

Vivek
[ June 11, 2008: Message edited by: Vivek Bakshi ]
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Where does your #145 or blah.... values are coming... are these also dynamically generated or user defined?


When a user registers with the application they are assigned an ID number. The ID number is generated by the application. When a user registers, a set of tables will be created in the database (for expense records, transactions, sales data, etc.)

Thanks for sending the link. I will check it out when I get a chance and see what it do


After a few discussions about this, I think this would require a newly configured SessionFactory, if it were to work. Currently, the SessionFactory is configured with the data in the configuration file when application is deployed. We need a dynamic SessionFactory which is configured at runtime in the code using runtime values. It seems possible, not sure if with the current verison of Hibernate. Maybe a future enhancement.
[ June 11, 2008: Message edited by: James Clark ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate: Dynamic Table Mapping