java 什么类型的数据记录带有注解@Lob with JPA?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14078078/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 14:59:06  来源:igfitidea点击:

What type of data record with the annotation @ Lob with JPA?

javahibernatejpalob

提问by MiguelCPJava

I have a problem, When I'm recording a PDF file inside the bank, I better save as file or byte []?

我有一个问题,当我在银行内录制PDF文件时,我最好保存为文件或字节[]?

@Lob @Basic(fetch=FetchType.EAGER)
@Column(name="arqdocumento")
private File arquivo; 

or

或者

@Lob
@Basic(fetch=FetchType.EAGER)
@Column(name="arqdocumento")
private byte[] arquivo; 

And how do I get this file from database and display in the browser?

以及如何从数据库中获取此文件并在浏览器中显示?

I wonder why I do it this way:

我想知道为什么我这样做:

public File getDocumentoBinary(int iDdocumento){
   Query consulta = getSesseion().createSQLQuery("SELECT arqdocumento FROM documento WHERE iddocumento = :id");
   consulta.setInteger("id", iDdocumento);
   return  (File) consulta.uniqueResult();     }

but displays this error:

但显示此错误:

Caused by: org.hibernate.MappingException: No Dialect mapping for JDBC type: -4

引起:org.hibernate.MappingException:JDBC 类型没有方言映射:-4

回答by MGPJ

@Lob
@Basic(fetch=FetchType.EAGER)  
@Column(name="arqdocumento")  
private byte[] arquivo;  

is the correct approach to store the huge amount of data in the DB. Your error says you have to include the Dialect in the persistence.xml file. So verify you have entered the correct Dialect property.

是在数据库中存储大量数据的正确方法。您的错误表明您必须在 persistence.xml 文件中包含方言。因此,请确认您输入了正确的方言属性。

回答by Perception

Use a byte array, or InputStream, or a SQL blob type. You cannot map a blob column to a File.

使用字节数组、InputStream 或 SQL blob 类型。不能将 blob 列映射到文件。