How can map dynamic physical table with Entity?

I want to implement a use case, using hibernate.

A certain draw which is created daily,
That drawid is unique for Draw.

Using drawid of the draw, each day dynamically a physical table created. Example. trip_{drawid} (trip_1, trip_2) , this table created on daily basis. And having the same column in all table that is created dynamically. And each day huge record is inserted.

How can I implement in hibernate because each day if new physical table created, then I have to created a java class entity (@Entity ( trip_1)). ?
How can I make it generic?
Is it feasible?

Is it feasible?

It does not sound like a good design to me. Why create a new table on a daily basis? And what does huge mean anyway?

You could use a JSON column if you want to store unstructured data, Check out the hibernate-types project if you want to map JSON properties.

And what does huge mean anyway?

on average 80,000 records are inserted, if we keep it in only one table, in one year this would be 80000 * 30 * 12 (approx). Fetching record from this table become time-consuming as we analyze each draw on a daily basis.

I agree with “It does not sound like a good design to me”, but our data is structural that is why i wanted to do like as queried .

[quote=“piyush_Raghuvanshi, post:3, topic:2067”]
On average, 80,000 records are inserted, if we keep it in only one table, in one year this would be 80000 * 30 * 12 (approx)[/quote]

Having 29 million records per year is not out of the ordinary. Most relational database systems are designed to sore more than that.

Fetching record from this table become time-consuming as we analyze each draw on a daily basis.

Not necessarily. There are applications that have tables with billions of records, and performance is very good. As long as you use indexing and filter records so that you can fetch a small percentage of a table, you should be fine.

I agree with “ It does not sound like a good design to me ”, but our data is structural that is why i wanted to do like as queried .

You don’t need to create a new table per day. What you need is table partitioning. Basically, you try to do table partitioning manually, while the RDBMS can do that for you transparently.

So, the solution is to refactor your schema to make use of what the RDBMS already has to offer.

1 Like