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

10,424
@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.

Share:
10,424
MiguelCPJava
Author by

MiguelCPJava

Updated on June 14, 2022

Comments

  • MiguelCPJava
    MiguelCPJava almost 2 years

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

    @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

  • MiguelCPJava
    MiguelCPJava over 11 years
    Thanks Everybody, but this error I think that´s something with with the query, exist another way for search this file in database with the Criteria API or other way? I´m using org.hibernate.dialect.MySQLDialect.
  • MiguelCPJava
    MiguelCPJava over 11 years
    I found the solution, the query is certain what was causing the error was the component p: commandButton inside a p: dialog.Então changed the button to h: commandButton and no longer had the error.