使用 hibernate 时我遇到了架构验证问题。该错误非常简单,它表示我的代码中预期的列类型和实际找到的列类型不匹配。
但据我所知,它们确实匹配。在查看类似问题后,我添加了columnDefinition =“int(10)”,但这没有帮助。任何帮助或指示进一步查看什么将不胜感激。
类定义和变量声明
轨迹类
public class Traject implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id", columnDefinition="int(10)")
private int id;
@OneToMany (fetch = FetchType.EAGER, mappedBy = "traject")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "toets_bij_traject")
@JsonBackReference
@OrderBy("toetsInSerie ASC")
private Set<ToetsBijTraject> toetsenBijTraject;
other vars and methods not shown
ToetsBijTraject 类
@Entity
@Table(name = "tt_traject_ref_toets")
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE, region="")
public class ToetsBijTraject implements Serializable, Comparable<ToetsBijTraject> {
@Id
@Column(name = "traject_id")
private Traject traject;
@Id
@Column(name = "toets_id")
private Toets toets;
other vars and methods not shown
工作台轨迹
CREATE TABLE `traject` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`naam` varchar(20) NOT NULL,
`is_actief` tinyint(1) DEFAULT '1',
PRIMARY KEY (`id`),
UNIQUE KEY `naam` (`naam`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1;
CREATE TABLE `tt_traject_ref_toets` (
`traject_id` int(10) unsigned NOT NULL,
`toets_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`traject_id`,`toets_id`),
KEY `toets_id` (`toets_id`),
CONSTRAINT `tt_traject_ref_toets_ibfk_1` FOREIGN KEY (`traject_id`)REFERENCES `traject` (`id`),
CONSTRAINT `tt_traject_ref_toets_ibfk_2` FOREIGN KEY (`toets_id`)
REFERENCES `ref_toets` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
错误信息:
Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [traject_id] in table [tt_traject_ref_toets]; found [int (Types#INTEGER)], but expecting [tinyblob (Types#VARBINARY)]
at org.hibernate.tool.schema.internal.SchemaValidatorImpl.validateColumnType(SchemaValidatorImpl.java:105)
at org.hibernate.tool.schema.internal.SchemaValidatorImpl.validateTable(SchemaValidatorImpl.java:92)
at org.hibernate.tool.schema.internal.SchemaValidatorImpl.doValidation(SchemaValidatorImpl.java:50)
at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:91)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:484)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:802)
... 87 more