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?
Databases use the data types BLOB (binary large object) and CLOB (character large object) to store large objects, like images and very long texts. JPA and Hibernate provide two kinds of mappings for these types. You can choose if you want to: Materialize the LOB and map it to a byte[] or a String.
Hibernate is an implementation of JPA. Hence, the common standard which is given by JPA is followed by Hibernate. It is a standard API that permits to perform database operations. It is used in mapping Java data types with SQL data types and database tables.
There's such an example is the JPA spec (§ 9.1.5)
@Column(name="DESC",
columnDefinition="CLOB NOT NULL",
table="EMP_DETAIL")
@Lob
public String getDescription() { return description; }
I believe it's the standard way for CLOB.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With