Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在PostgreSQL中使用JPA2存储字节数组图像_Java_Hibernate_Postgresql - Fatal编程技术网

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可以看到数值。否则我会看到
二进制数据
。我的问题是:

  • 是否有可靠的方法使用JPA2存储和读取二进制数据
  • 有没有办法读取postgres中的二进制数据?因为现在我不确定它们是否正确存储

  • PostgreSQL中列的类型是什么?如果数据小于几兆字节,我建议使用
    BYTEA
    。它通常将cleaner映射到ORM中。当我使用我的主要帖子中提到的Anotation时,你可能想读一读,类型是BYTEA。您知道如何查看/保存其内容吗?