You need to transform a String into a CLOB. JBoss 6 uses Hibernate 3.6 and there are some changes to the CLOB/BLOB creation. You need to access Hibernate session to get a reference to a LobHelper implementation.

 

There're two ways how you can access the session:

  1. You can inject your Persistence context into a org.hibernate.Session variable, see Bill Burke's blog here
  2. You access the infamous getDelegate() method and cast to org.hibernate.Session, i.e. something like:

 

{code:java}

@PersistenceContext(

            unitName = "MY_UNIT")

    private EntityManager eMan;

//in some method

String strText = "A very long text";

org.hibernate.Session se = (org.hibernate.Session) eMan.getDelegate();

LobHelper lh = se.getLobHelper();

Clob cl = lh.createClob(strText);

{code}

Why "infamous"? The books I read about EJB3 told me to be careful when using specific JPA implementation features (in this case, Hibernate), i.e. the application will be tied to this particular implementation of the JPA.

 

See the Hibernate API on LobHelper for further methods.

 

UPDATE:

Unfortunately, I hit this documented bug: the cast into Oracle Clob doesn't work. The link contains also the workaround. Basically, you have to use a String field instead of Clob. Something like this:

 

{code:java}

@Lob

    @Basic(

            fetch = FetchType.LAZY)

    @Type(

            type = "org.hibernate.type.StringClobType")

    private String someStuff;

{code}

So you don't need the LobHelper at all in this case.