开发者

How to map 2 table to 1 entity class with hibernate annotation?

I am new to Hibernate. Now I have a problem. I have 2 tables (Timetable, and Timetable_backup) with similar structu开发者_Go百科re because the timetable_backup table is just back up version of timetable table which contains current data. Now I do not know how to get all data from the past to now. In hibernate, we cannot use UNION like in SQL to query. So I try to map 2 tables to 1 entity using Inheritance and @mappedsuperclass but it does not work for me. Please help me with this. If the context is not clear please tell me.

Kind Regards

Nathan


Probably what you want is something like Envers, a plugin for Hibernate that takes care of versioning records in a table. You just use a couple of annotations in your classes and it provides an interface to look for past records among other things.


You cannot do it.

The typical workaround is to map entity to the main table, and use native SQL queries to access the backup table.


By this time you might have found answer or workaround to the problem you have posted. If possible, can you please post it here so that it will help others.

Anyway I found following link which explains how to create tables using single POJO Mapping same POJO to more than one table in Hibernate.

As hibernate does not support union. I have extracted results from 2 queried (main table as well as backup table) and used listTimeTable.addAll(listbackTimeTable); This will give result same as union all operation.

Once again, please post your implementation for benefit of this community...

Thanks,

Shirish

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜