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