We have a product which runs in mysql, oracle and sqlserver. We are writing one custom module which needs to access a customer table and retrieve data. We are writing it using spring data JPA. For this we have Customer pojo as below and created a Repository.
Note that the columns are case sensitive. The POJO that works for oracle is as below,
import lombok.*;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Getter
@Setter
@ToString
@Table(name="customer")
public class Customer{
@Id
@Column(name="\"cxCifID\"")
private String cxCifID;
@Column(name="\"hostCustId\"")
private String hostCustId;
@Column(name="\"custMobile1\"")
private String custMobile1;
@Column(name="\"custEmail1\"")
private String custEmail1;
@Column(name="\"custName\"")
private String custName;
@Column(name="\"custMotherTongue\"")
private String custMotherTongue;
}
The same will not work in mysql and will give the error as below,
"Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"cxCifID" as cxcifid1_0_, customer0_."custEmail1" as custemai2_0_, customer0_."c' at line 1"
If i use the below POJO for mysql it works without error,
import lombok.*;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Getter
@Setter
@ToString
@Table(name="customer")
public class Customer{
@Id
@Column(name="cxCifID")
private String cxCifID;
@Column(name="hostCustId")
private String hostCustId;
@Column(name="custMobile1")
private String custMobile1;
@Column(name="custEmail1")
private String custEmail1;
@Column(name="custName")
private String custName;
@Column(name="custMotherTongue")
private String custMotherTongue;
}
The question is how can I create and use a single POJO which can be used in both the databases or in fact in all the databases? Please help