convert String to Clob and vice versa in Hibernate

后端 未结 3 1986
北海茫月
北海茫月 2021-01-05 04:30

Suppose that I have a Class:

class EventTransaction {
    .....
    private Clob dataXML;

    public Clob getDataXML() {
       return dataXML;
    }

    p         


        
3条回答
  •  無奈伤痛
    2021-01-05 04:51

    The limitation of 64000 characters is on the database side when you declare the XML column as VARCHAR (and not on Java String), so as long as your column XML is a CLOB, it should work.

    Excerpt from working code:

    Entity:

    private String xml;
    

    SQL (ORACLE):

    XML       CLOB,
    

    Hibernate mapping:

    
        
    
    

    If you want to store the XML as a file, then you should rather use BLOBs as shown below :

    Entity:

    private byte[] xmlFile;
    

    SQL (ORACLE):

    XML       BLOB,
    

    Hibernate mapping:

    
        
    
    

提交回复
热议问题