I am building a spring rest API which will return promo information (promo_code, promo_description, efective_date,expiration_date) and I have the table structure like blow
PROMO_DETAIL SEQ_NO NUMBER(9), //PK PROMO_CODE VARCHAR2(9), //PK PROMO_DESCRIPTION VARCHR2(100), EFFECTIVE_DATE DATE, EXPIRATION_DATE DATE I am using an entity class having promo_code,promo_description,effective_date and expiration_date. I annotated only promo_code with @Id. I am directly returning the entity class as the response.
Problem is when there is 2 records with same promo code(but with different values of other fields). Though In this case JPA returns two records however both records have duplicate values for all fields.
Same type of question was asked here as well "JPA/Hibernate select query returning duplicate records"
Solution is to composite key in entity.
I do not want to add seq_no to entity class because it is not required in response. I also do not want to create unnecessarily separate response model class. It will create extra overhead of mapping entity to model class.
Is there any other solution to this problem?