Convert entity column values on the basis of other entity column in spring boot using AttributeConverter

Viewed 211

I want to set a particular entity column value manually. For example, let's say billid has value "bid123" in the database. Firstname is "ABC" and lastname is "XYZ". I want to set the billid value as billid+""+firstname+""+lastname i.e. "bid123_ABC_XYZ".

@Getter
@Setter
@ToString
@Entity
public class PreviousInvoiceSearchResult {

  @Id
  @Column(name = "summaryid")
  private Long summaryId;

  @Column(name = "custID")
  private String custId;

  @Column(name = "firstName")
  private String firstName;

  @Column(name = "lastName")
  private String lastName;

  @Column(name = "billID")
  private int billId;
}

I am able to do this by iterating through Entity object in service implementation. But i have so many columns like billid. i got to know about AttributeConverter in JPA but i am not able to implement it using that.

Is there a way to do this using AttributeConverter of JPA or by any other method which doesn’t involve iterating through Entity object in service implementation?

0 Answers
Related