【发布时间】:2018-11-12 15:06:52
【问题描述】:
我想使用这个类在我的数据库上创建新表
@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
}
当我尝试使用属性运行我的应用程序时
spring.jpa.hibernate.ddl-auto=create
我遇到了这个异常
引起:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 指定的密钥太长;最大密钥长度为 1000 字节
看起来我不能使用 Spring 作为我的 ID?将类型更改为 Long 可以解决问题,但我真的很想用 String 来解决这个问题。根据我的搜索,它应该是完全可行的。
【问题讨论】:
-
@YassinHajaj:不,它不是重复的。请不要生成垃圾邮件。如果您无法准确判断这是否是重复的,请在查看问题时按 SKIP。低质量的问题和低质量的问题一样糟糕。
-
@mentallurg 这就是为什么句子以 Possible duplicate of 开头的原因
标签: mysql spring spring-data