我是休眠的新手。我需要将文件存储在 postgres 中,列的数据类型是bytea
. 我在互联网上四处寻找这个案例的工作演示,但我找不到任何东西。
休眠映射:
<property name="fileData" type="binary"> <column name="fileData" not-null="true" /> </property>
POJO:
私有字节[] 文件数据; 公共字节[] getFileData() { 返回文件数据; } 公共无效setFileData(字节[]文件数据){ this.fileData = 文件数据; }
桌子 :
创建表 nmonData(id int, buildNumber int, path text, fileName text, fileData bytea);
错误 :
org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [fileData] in table [nmondata]; found [bytea (Types#BINARY)], but expecting [binary(255) (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:473)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
at com.psl.perf.hibernate.util.HibernateUtil.<clinit>(HibernateUtil.java:34)
at com.psl.perf.DAO.NmonReportFileDaoImpl.save(NmonReportFileDaoImpl.java:15)
at com.psl.perf.service.DataService.saveNmonCSV(DataService.java:249)
at com.psl.perf.main.Main2.main(Main2.java:8)
Jan 22, 2016 12:26:18 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop
INFO: HHH10001008: Cleaning up connection pool [jdbc:postgresql://x.x.x.x:5432/perf]
Exception in thread "main" java.lang.NullPointerException
at com.psl.perf.DAO.NmonReportFileDaoImpl.save(NmonReportFileDaoImpl.java:17)
at com.psl.perf.service.DataService.saveNmonCSV(DataService.java:249)
at com.psl.perf.main.Main2.main(Main2.java:8)
有人可以分享工作演示或链接吗?
这对我有用,在休眠配置文件中 评论 对我有用
<property name="hbm2ddl.auto">validate</property>
,但是我现在对用于存储文件的 java 中列和成员变量的数据类型应该是什么感到困惑。