Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate: Dynamic Table Mapping

 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic