为什么不能将JPA / hibernate映射到MySQL blob类型? [英] Why cant JPA/hibernate map to MySQL blob type?
本文介绍了为什么不能将JPA / hibernate映射到MySQL blob类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到以下错误:
引起:org.hibernate.HibernateException:列PAYLOAD中TestTable的列类型错误。 Found:blob,expected:tinyblob
at org.hibernate.mapping.Table.validateColumns(Table.java:284)
at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1174)
at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:139)
at org.hibernate.impl.SessionFactoryImpl。< init>(SessionFactoryImpl.java:387)
在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1385)
在org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954)
在org.hibernate.ejb.Ejb3Configuration .buildEntityManagerFactory(Ejb3Configuration.java:883)
... 60 more
列休眠正在抱怨声明为
private byte [] messagePayload;
@Column(name =PAYLOAD)
public byte [] getMessagePayload(){
return messagePayload;
}
public void setMessagePayload(byte [] messagePayload){
this.messagePayload = messagePayload;
$ / code>
MySQL表中的表被声明为BLOB类型。为什么Hibernate不想映射它,为什么它坚持使用TINYBLOB?
谢谢
解决方案
您可以尝试显式设置blob类型使用 columnDefinition 属性。像这样:
@Column(name =PAYLOAD,columnDefinition =blob)
$ c
或使用@Lob注解:
@Column(name =PAYLOAD)
@Lob(type = LobType.BLOB)
I got the following error
Caused by: org.hibernate.HibernateException: Wrong column type in TestTable for column PAYLOAD. Found: blob, expected: tinyblob
at org.hibernate.mapping.Table.validateColumns(Table.java:284)
at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1174)
at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:139)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:387)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1385)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:883)
... 60 more
The column hibernate is complaining about is declared as
private byte[] messagePayload;
@Column(name="PAYLOAD")
public byte[] getMessagePayload() {
return messagePayload;
}
public void setMessagePayload(byte[] messagePayload) {
this.messagePayload = messagePayload;
}
The table in the MySQL table is declared as a BLOB type. Why doesnt Hibernate want to map to it and why does it insist that i use TINYBLOB?
Thanks
解决方案 You could try to set explicitly the type blob with columnDefinition attribute. Like this:
@Column(name="PAYLOAD",columnDefinition="blob")
Or use the @Lob annotation:
@Column(name="PAYLOAD")
@Lob(type = LobType.BLOB)
这篇关于为什么不能将JPA / hibernate映射到MySQL blob类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文