GeeCON Prague 2014*
The moose likes Object Relational Mapping and the fly likes Need to create a dynamic table with dynamic name in hibernate.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Need to create a dynamic table with dynamic name in hibernate...." Watch "Need to create a dynamic table with dynamic name in hibernate...." New topic
Author

Need to create a dynamic table with dynamic name in hibernate....

john sal
Ranch Hand

Joined: Jul 30, 2010
Posts: 93
In my application we are using database table to store all the log. But now there is a change in requirement and instead of storing all the log related data in one table we have to create a table for that particular day and will have to store all the user logs int the table for that day....for Eg if today's date is 10 Aug then for storing a log a new database table will be created log_10_aug and all the data related to the current day will be stored in it... for next day again a new table will be created for storing the next day log activity..


We are using the Hibernate ORM in our application.....

Can someone let me know how to achieve the same using hibernate....how can we create the table dynamically with dynamic name....using hibernate...intent is that table strucuture will remain same however for each day the table name will be differenct (log_ preceeded by current date) ..
Vijay Tidake
Ranch Hand

Joined: Nov 04, 2008
Posts: 146

Hi,

I'm following may be one way to create the table at run time using hibernate.



Hope this helps
Thanks


The important thing is not to stop questioning.Curiosity has its own reason for existing.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Why would you want separate tables? Why not just select by the date the log-entry was created? If it is for performance reasons (i.e. your table has millions and millions of rows (and even then ...)) why not move the rows to another table once every x days.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Rebecca Green
Greenhorn

Joined: Dec 25, 2009
Posts: 16
@Vijay Tidake, Your code shows how to create dynamic tables, but once these tables are created, how will i access them, I mean i need to create hbm files and also, i should include it in the hibernate.cfg file. How will I do that?

Vijay Tidake wrote:Hi,

I'm following may be one way to create the table at run time using hibernate.



Hope this helps
Thanks
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3833

Hi Rebecca Green,

Is your question is same as Vijay Tidake's? If not please create new thread for yours'.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Rebecca Green
Greenhorn

Joined: Dec 25, 2009
Posts: 16
It is very much relevant to Vijay Tidake's post. I came up with this doubt after reading Vijay's post.

Vijitha Kumara wrote:Hi Rebecca Green,

Is your question is same as Vijay Tidake's? If not please create new thread for yours'.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3833

As there's not much details given by the OP and no other solutions are discussed you may need to clarify your situation properly. I suggest you start a new thread with more details in it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need to create a dynamic table with dynamic name in hibernate....