What is the alternate for deprecated Hibernate.createClob(Reader reader, int length)

寵の児 提交于 2019-11-30 09:20:59

问题


Seems like Hibernate.createClob(Reader reader, int length) is deprecated in version 3.6.x And it suggests to use Use LobHelper.createClob(Reader, long) instead.

But LobHelper is an interface not a class.

Is there any alternate for static method Hibernate.createClob(Reader reader, int length)?


回答1:


I was using the createBlob(bytes[]) from that class. I created a new class and the following method

    public static Blob createBlob(byte[] bytes) {
       return NonContextualLobCreator.INSTANCE.wrap(NonContextualLobCreator.INSTANCE.createBlob(bytes));
    }



回答2:


It is the way of simplifying the usage by hiding the implementations. If you want to use the Clob data you need to use the below code. I have tested it in version hibernate 3.6.

session.getLobHelper().createClob("the_string");

Now coming your second point about the working of it, if you read the source code of org.hibernate.impl.SessionImpl class you will know how internally hibernate handles this.

public LobHelper getLobHelper()
/*      */   {
/* 2245 */     if (this.lobHelper == null) {
/* 2246 */       this.lobHelper = new LobHelperImpl(this, null);
/*      */     }
/* 2248 */     return this.lobHelper;
/*      */   }



回答3:


I have found another good alternate for this, using java javax.sql.rowset.serial.SerialClob

For example

Clob clob = new SerialClob("Some very long String.......".toCharArray());


来源:https://stackoverflow.com/questions/9304211/what-is-the-alternate-for-deprecated-hibernate-createclobreader-reader-int-len

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!