We are generating Sales Report using Hibernate.
Scenario
When user clicks on generate report button after entering some criteria, I am fetching data from database using hibernate, then we are doing some data manipulation to generate actual report data. Report data is stored in ArrayList, which then persisted into database in CommissionSummary table, which is mapped with hibernate entity as below
CommussionSummary.java
@Column(length=100)
private String advisorName;
private String advisorCodeParent;
@Column(length=100)
private String advisorNameParent;
@Column(length=100)
private String advisorPost;
@Column
private Double percentage;
@Column
private Double diffPercentage;
@Column
private Double saleAmount;
@Column
private Long saleCount;
@Column
private Double commissionAmount;
@Column
private Integer month;
@Column
private Integer year;
Report is generated for every month.
My Question is: For 05 July 2012 user has generated data so i am storing this information in CommissionSummary table. Now user has generating the same report on 15 July 2012, then it should override earlier month data.
Override criteria should be month and year.
I believe what you need is a simple data checking.
Solution One:
1. Load data from DB and check those data for possible duplication.
2. If you find them equal, delete the older version.
Solution Two:
One other possible solution is to define your columns unique, so if a user wants to put the same data, he will be receiving some exceptions. Something like this:
Using this, you can check if there were some errors you can do your desired action.