Which Hibernate annotation to use for clob

0

I have an attribute that takes a string and must be persisted in a clob in the oracle sql. I looked in the documentation that should be used annotation @Lob:

  

@Lob indicates that the property should be persisted in a Blob or a   Clob, depending on the property type: java.sql.Clob, Character [],   char [] and java.lang.String will be persisted in a Clob.   java.sql.Blob, Byte [], byte [] and serializable type will be persisted   in a Blob.

@Lob
public String getFullText() {
    return fullText;
}

@Lob 
public byte[] getFullCode() {
    return fullCode;
}

But it's not clear whether I just import sql.clob or need to do something else. The attribute code I use:

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import java.sql.Clob;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name = "COMENTARIOS")
public class Comentario implements Serializable, Cloneable {

    private static final long serialVersionUID = -7272795930725483134L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "entity_sequence_generator_comentario")
    @SequenceGenerator(name = "entity_sequence_generator_comentario", sequenceName = "comentario_seq")
    @Column(name = "id", nullable = false)
    private int id;

    @Lob
    @Column(name = "BODY", nullable = false)
    private String body;

Bank:

CREATE TABLE comentarios (
    id NUMBER(11) NOT NULL,
    id_receita NUMBER(11) NOT NULL,
    id_usuario NUMBER(11) NOT NULL,
    body CLOB NOT NULL);
    
asked by anonymous 07.05.2018 / 05:39

0 answers