I have a Spring Boot application where I need to insert an object to a redshift table. No problem with manual insertion of data using a query. But I'm facing a challenge while persisting data to Amazon Redshift table from my Spring Boot app. Redshift table was created using the below query:
create table demand_test(id int not null identity(1,1), dateOfrequest DATE, country varchar(100), primary key(id))
So, I created a model class as shown below:
@Entity
@Table(name = "demand_test")
public class Demand implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column
@GeneratedValue(strategy=GenerationType.IDENTITY)
private BigInteger id;
@Column
@DateTimeFormat(pattern = "dd/MM/yyyy")
private Date dateofrequest;
@Column
private String country;
public BigInteger getId() {
return id;
}
public void setId(BigInteger id) {
this.id = id;
}
public Date getDateofrequest() {
return dateofrequest;
}
public void setDateofrequest(Date dateofrequest) {
this.dateofrequest = dateofrequest;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
}
When I try to insert Demand
object, I get the below error:
com.amazon.support.exceptions.ErrorException: [Amazon](500310) Invalid operation: relation "demand_test_id_seq" does not exist;
at com.amazon.redshift.client.messages.inbound.ErrorResponse.toErrorException(ErrorResponse.java:1830) ~[redshift-jdbc42-1.2.1.1001.jar:RedshiftJDBC_1.2.1.1001]
at com.amazon.redshift.client.PGMessagingContext.handleErrorResponse(PGMessagingContext.java:822) ~[redshift-jdbc42-1.2.1.1001.jar:RedshiftJDBC_1.2.1.1001]
at com.amazon.redshift.client.PGMessagingContext.handleMessage(PGMessagingContext.java:647) ~[redshift-jdbc42-1.2.1.1001.jar:RedshiftJDBC_1.2.1.1001]
I see a number of posts that are similar and were posted a couple of years back with no answers. I tried to filter out this issue to Hibernate specific, but I have no luck so far on this. I have been trying out various options such as:
- using
GenerationType.AUTO
- removing
@GeneratedValue(strategy=GenerationType.IDENTITY)
I'm not sure why I'm getting this error with sequence since I'm using only IDENTITY
generation type for the column.The JpaRepository
save()
method throws the mentioned error. What's going wrong here?