English 中文(简体)
根据某些条件绘制的不同表格的地图
原标题:Map Entity to different Tables based on certain condition

我有一个名为“交易”的实体,其数据库的相关表格是TAB。 页: 1 整个系统都在做高额工作;现在出现了一项新的要求,即客户要求将所有30天以上的交易转到另一个档案表,例如,。 TAB_TRANSACTIONS_HIST.

Currently as a work around I have given them a script scheduled to run every 24 hours, which simply moves the data from Source to Dest.

我不禁要问,是否利用藏匿地更好地解决这一问题?

Can I fetch Transaction entities, 然后将其储存在TAB_ 交通部 HISTORY? 我研究了许多类似问题,但无法找到解决办法,任何建议都会有所帮助。

最佳回答

您不妨为这项任务设定一个季度时间表。 页: 1

public class DatabaseBackupJob implements Job {
    public void execute(JobExecutionContext jec) throws JobExecutionException {
        Configuration cfg=new Configuration();
        cfg.configure("hibernate.cfg.xml");
        Session session = cfg.buildSessionFactory().openSession();
        Query q = session.createQuery("insert into Tab_Transaction_History(trans) select t.trans as trans from Tab_Transaction t where t.date < :date")
        .setParameter("date", reqDate);
        try{
           Trasaction t = session.beginTransaction();
           q.executeNonQuery();
           t.commit();
        } catch(Exception e){
        } finally {
           session.close();
        }
    }

}

P.S. hibernate没有提供时间表,因此,你无法利用核心自由进行这项活动,因此,需要外部的APIC,如:

问题回答

我认为,只有依靠传统技术大学的不同持久性环境,你才能找到解决办法。

A single persistence context maps entities to tables in a non-dynamic way, so you can t perform a "runtime-switch" from a mapped-table to another. But you can create a different persistence context (or a parallel configuration in hibernate instead of using 2 different contexts), then load this new configuration in a different EntityManager, and perform all your tasks.

这是目前唯一的解决办法。 真正不知道它是否充分......

I think it s a good idea to run the script every 24 hours. You could decrase the interval if you re not happy.

But if you already have a working script, where is your actual problem? Checking the age of all transactions and move the ones older than 30 days to another list or map is the best way I think.

你们将需要某种时间表机制。 要么是直线read,要么是适合你的其他触发器。

也可使用大宗加操作

Query q = session.createQuery(
"insert into TabTransactionHistory tth
(.....)
select .... from TabTransaction tt"
);
int createdObjects = q.executeUpdate();

(地点......实际作业地区)

你们也可以使用“哪一条款”来根据这些条目的老旧来计算结果。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签