Java 在PostgreSQL中使用JPA2存储字节数组图像
我试图在数据库中存储一个图像,但当我读取该值时,我总是得到空值 我尝试了以下注释的几种组合,但结果总是一样的:Java 在PostgreSQL中使用JPA2存储字节数组图像,java,hibernate,postgresql,Java,Hibernate,Postgresql,我试图在数据库中存储一个图像,但当我读取该值时,我总是得到空值 我尝试了以下注释的几种组合,但结果总是一样的: @Lob @Basic(fetch = FetchType.EAGER) @Type(type="org.hibernate.type.BinaryType") private byte[] image; persistence.xml: <persistence-unit name="primary" transaction-type="JTA"> <jt
@Lob
@Basic(fetch = FetchType.EAGER)
@Type(type="org.hibernate.type.BinaryType")
private byte[] image;
persistence.xml:
<persistence-unit name="primary" transaction-type="JTA">
<jta-data-source>java:jboss/datasources/WheelGoDS</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create" />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name="hibernate.current_session_context_class" value="jta"/>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.archive.autodetection" value="class" />
<property name="hibernate.connection.useUnicode" value="true" />
<property name="hibernate.connection.characterEncoding" value="UTF-8" />
</properties>
</persistence-unit>
java:jboss/datasources/WheelGoDS
当我只使用@Lob
时,我注意到使用pgAdmin可以看到数值。否则我会看到二进制数据
。我的问题是:
PostgreSQL中列的类型是什么?如果数据小于几兆字节,我建议使用
BYTEA
。它通常将cleaner映射到ORM中。当我使用我的主要帖子中提到的Anotation时,你可能想读一读,类型是BYTEA。您知道如何查看/保存其内容吗?