简体   繁体   English

在hibernate从DB检索数据后计算值

[英]Calculate values after hibernate retrieves data from DB

We're using hibernate for school, and we're implementing loans. 我们正在学校使用hibernate,我们正在实施贷款。 We have a Loan class which is persistent, and depending on the information on the loan (amount of payments, total due etc.) the app should calculate the entire payment quotes for the specific loan. 我们有一个持久的贷款类别,根据贷款信息(付款金额,到期金额等),应用程序应计算特定贷款的全部付款报价。

So we have a Quote class with the information regarding that quote and the Loan class has a list of all its quotes (composition between the classes). 所以我们有一个Quote类,其中包含有关该引用的信息,Loan类包含所有引号的列表(类之间的组合)。

Since the quote information is calculable, I think it shouldn't be on the DB. 由于报价信息是可计算的,我认为它不应该在DB上。

My question specifically is , how do I get Hibernate to calculate and populate the list of quotes when it brings up a Loan from the DB. 我的问题具体是,如何在从数据库中调出贷款时让Hibernate计算并填充引号列表。

Clarification: Loan class has a method for calculating and populating it's list of quotes, I can't figure out the way to make it run when hibernate retrieves it from the DB. 澄清: Loan类有一个计算和填充它的引号列表的方法,当hibernate从数据库中检索它时,我无法弄清楚它的运行方式。

Update: Since we have a data layer (where the Loan class is) and a business layer (where you actually work on the data, and in turn calls the DAO Layer), I have added a call to the method in the business layer right before I return the object from the DB. 更新:由于我们有一个数据层(Loan类所在的位置)和一个业务层(实际处理数据,然后调用DAO层),我在业务层右侧添加了对方法的调用在我从DB返回对象之前。 Is this best practice? 这是最佳做法吗? End update 结束更新

Thanks, 谢谢,

  1. Just because some data is calculable it doesn't imply that it shouldn't stored in the database. 仅仅因为某些数据是可计算的,并不意味着它不应该存储在数据库中。 In fact redundancy is often used to improve the performances of a system. 事实上,冗余通常用于改善系统的性能。 Besides, denormalized data are very useful for reports, stats and for business intelligence tools. 此外,非规范化数据对于报表,统计数据和商业智能工具非常有用。
  2. Having put the calculation of the Quote in the business layer could be a good choice but it depends on the context of your application. 将Quote的计算放在业务层中可能是一个不错的选择,但这取决于应用程序的上下文。 It is the Quote data used only to change the state of the system or it is rather used also in reports? 引用数据仅用于更改系统状态,还是在报告中使用? Do you expect much data in the database? 您是否期望数据库中包含大量数据? Will you need a stat of all Quotes of all loans? 您是否需要所有贷款的所有行情统计数据? Is it your application service oriented? 它是您的应用服务导向? Has it got an external report engine? 它有外部报告引擎吗? If any of these questions has yes as answer, you should consider store the computed data in the database 如果这些问题中的任何一个都是肯定的答案,您应该考虑将计算数据存储在数据库中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM