Mike Deck
Mike Deck

Reputation: 18397

Bind Hibernate entity to table at runtime

I have a database schema that contains multiple tables with different names, but all have the exact same column structure. The database contains historical log data with one table per day.

I'd really like to be able to create a Hibernate mapping for the columns that I could reuse for each table. Essentially I need a way to pass in a table name either when I create a session or when I execute a query. I don't think Hibernate supports this, but I'd be interested to hear if anyone has an idea about how I could handle this situation.

Upvotes: 4

Views: 2942

Answers (2)

Tom Carter
Tom Carter

Reputation: 2976

I think you want to implement a Naming Strategy

Here's a link to a discussion for a similar problem to yours

Upvotes: 3

If you are only interested in data read, you could use the ResultTransformer to load the data from statement.

Upvotes: 1

Related Questions