运行时将Hibernate实体绑定到表 [英] Bind Hibernate entity to table at runtime
问题描述
我有一个数据库模式,其中包含具有不同名称的多个表,但都具有完全相同的列结构。该数据库包含每天有一个表的历史日志数据。
我真的很想为每个表可以重复使用的列创建一个Hibernate映射。从本质上讲,我需要一种方法来在创建会话或执行查询时传递表名称。我不认为Hibernate支持这一点,但我很想听听有没有人对我如何处理这种情况有所了解。
解决方案 div>我想你想实现一个命名策略
以下是 link 与您讨论类似问题
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.
I think you want to implement a Naming Strategy
Here's a link to a discussion for a similar problem to yours
这篇关于运行时将Hibernate实体绑定到表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!