How to create a Clob in JPA in an implementation agnostic way

Posted by kazanaki on Stack Overflow See other posts from Stack Overflow or by kazanaki
Published on 2010-04-14T11:53:09Z Indexed on 2010/04/14 21:23 UTC
Read the original article Hit count: 561

Filed under:
|
|
|

Hello

I am using Ejb3 and JPA (based on Hibernate and Oracle 10g at the moment)

I have an entity that contains a clob

@Entity
@Table(name = "My_TAB")
public class ExampleEntity implements java.io.Serializable {

    private Clob someText;

    public void setSomeText(Clob someText) {
        this.someText= someText;
    }

    @Column(name = "COLUMN_NAME")
    public Clob getSomeText() {
        return this.someText;
    }

Then I want to save an entity of this type.

At the moment I am doing the following which works perfectly

ExampleEntity exampleEntity = new ExampleEntity();
exampleEntity.setSomeText(Hibernate.createClob(aStringValue));
someOtherDao.save(exampleEntity);

However this ties my code to Hibernate! I have specifically avoided so far Hibernate extensions and used only JPA annotations. The code works because indeed Hibernate is my current implementation.

Is there some sort of JPA API that allows me to create a clob in a generic way? So if later I decide to switch to Toplink/EclipseLink or something else I won't have to change a thing?

© Stack Overflow or respective owner

Related posts about java

Related posts about jpa