I want to create new table on my database using this class
@Entity
@Table(name = "currency_rate")
public class CurrencyRate {
@Id
private String id;
@Column(name = "source_currency")
private String sourceCurrency;
@Column(name = "target_currency")
private String targetCurrency;
@Column(name = "exchange_rate")
private double exchangeRate;
@Column
private Date date;
@PrePersist
public void generateID() {
this.id = this.date.toString().replace("-", "") + sourceCurrency + targetCurrency;
}
//getters, setters
}
When I try to run my application with property
spring.jpa.hibernate.ddl-auto=create
I got this exception
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Specified key was too long; max key length is 1000 bytes
Looks like I can't use Spring as my ID? Changing type to Long solves problem, but I really wanted to go with String with this one. From what I searched, it should be totally doable.