作者:醒九九爷 | 来源:互联网 | 2022-12-03 14:44
当我尝试启动我的spring boot应用程序时,我得到此警告:
2018-09-30 07:34:23.097 INFO 59360 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
Hibernate: create table social_link (author_username varchar(255) not null, type varchar(255) not null, value varchar(255), primary key (author_username, type)) engine=MyISAM
2018-09-30 07:34:24.067 WARN 59360 --- [ main] o.h.t.s.i.ExceptionHandlerLoggedImpl : GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement
奇怪的是,我可以通过SQL工作台执行SQL语句而不会出现问题,然后一切正常。这是负责该表的实体:
@Entity
public class SocialLink {
@EmbeddedId
private SocialLinkKeyEmbeddable id = new SocialLinkKeyEmbeddable();
private String value;
@ManyToOne
@MapsId("author_username")
@JoinColumns({
@JoinColumn(name="author_username", referencedColumnName="author_username")
})
private Author author;
//Getters and setters
}
@Embeddable
public class SocialLinkKeyEmbeddable implements Serializable {
@Column(name = "author_username")
private String author_username;
private String type;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getAuthor_username() {
return author_username;
}
public void setAuthor_username(String author_username) {
this.author_username = author_username;
}
@Override
public int hashCode() {
return super.hashCode();
}
@Override
public boolean equals(Object obj) {
return super.equals(obj);
}
}
public interface SocialLinkRepository extends CrudRepository {
}
Boris Pavlov..
9
问题出在密钥的长度上。MySQL假装它大于1000个字节。MyISAM存储引擎似乎是一个普遍的问题。为了修复它,我添加了:
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL55Dialect
到我的applicaiton.properties,现在问题已解决。将此帖子用作参考
#1071-指定的密钥太长;最大密钥长度为1000个字节
1> Boris Pavlov..:
问题出在密钥的长度上。MySQL假装它大于1000个字节。MyISAM存储引擎似乎是一个普遍的问题。为了修复它,我添加了:
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL55Dialect
到我的applicaiton.properties,现在问题已解决。将此帖子用作参考
#1071-指定的密钥太长;最大密钥长度为1000个字节