In the CustomerTransactions entity, I have the following field to record what the customer bought:
@ManyToMany
private List<Item> listOfItemsBought;
When I think more about this field, there's a chance it may not work because merchants are allowed to change item's information (e.g. price, discount, etc...). Hence, this field will not be able to record what the customer actually bought when the transaction occurred.
At the moment, I can only think of 2 ways to make it work.
- I will record the transaction details into a String field. I feel that this way would be messy if I need to extract some information about the transaction later on.
- Whenever the merchant changes an item's information, I will not update directly to that item's fields. Instead, I will create another new item with all the new information and keep the old item untouched. I feel that this way is better because I can easily extract information about the transaction later on. However, the bad side is that my Item table may contain a lot of rows.
I'd be very grateful if someone could give me an advice on how I should tackle this problem.
UPDATE: I'd like to add more information about the current design.
public class Customer implements Serializable {
@OneToMany
private List<CustomerTransactions> listOfTransactions;
}
public class CustomerTransactions implements Serializable {
@ManyToMany
private List<Item> listOfItemsBought;
}
public class Merchant implements Serializable {
@OneToMany
private List<Item> listOfSellingItems;
}