休眠> CLOB> Oracle :( [英] Hibernate > CLOB > Oracle :(

查看:88
本文介绍了休眠> CLOB> Oracle :(的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试写入超过4000个字符的Oracle clob字段。这是一个共同的问题,但非解决方案似乎工作。



使用Oracle 9.2.0.8.0

Hibernate3使用注释实现pojo

Tomcat 6.0.16

Oracle 10.2.x驱动程序

C3P0连接池提供程序

在我的persistence.xml中,我有:

 < persistence-unit name =DWEBtransaction-type = RESOURCE_LOCAL> 
< provider> org.hibernate.ejb.HibernatePersistence< / provider>
<属性>
< property name =hibernate.archive.autodetectionvalue =class/>
< property name =hibernate.connection.passwordvalue =###/>
< property name =hibernate.connection.usernamevalue =###/>
< property name =hibernate.default_schemavalue =schema/>
< property name =hibernate.dialectvalue =org.hibernate.dialect.Oracle10gDialect/>
< property name =hibernate.c3p0.min_sizevalue =5/>
< property name =hibernate.c3p0.max_sizevalue =20/>
< property name =hibernate.c3p0.timeoutvalue =300/>
< property name =hibernate.c3p0.max_statementsvalue =50/>
< property name =hibernate.c3p0.idle_test_periodvalue =3000/>
< property name =show_sqlvalue =true/>
< property name =format_sqlvalue =true/>
< property name =use_sql_commentsvalue =true/>
< property name =SetBigStringTryClobvalue =true/>
< property name =hibernate.jdbc.batch_sizevalue =0/>
< property name =hibernate.connection.driver_classvalue =oracle.jdbc.driver.OracleDriver/>
< / properties>
< / persistence-unit>

getter和setter看起来像:

  @Lob 
@Column(name =COMMENT_DOC)
public String getDocument(){
return get(Document);
}
public void setDocument(String s){
put(Document,s);
}

我得到的异常是:

  SEVERE:servlet SW的Servlet.service()抛出异常
java.sql.SQLException:Io异常:软件导致连接中止:套接字写入错误
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess .DBError.throwSqlException(DBError.java:334)
在oracle.jdbc.ttc7.TTC7Protocol.handleIOException(TTC7Protocol.java:3678)
在oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java :1999)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1144)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2152)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:2035)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2876)
。在oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:609)
在org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:46)
在org.hibernate.persister .entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2275)
在org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2688)
在org.hibernate.action.EntityInsertAction.execute (EntityInsertAction.java:79)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
。在org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
在org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
。在组织。 hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.Sessi onImpl.flush(SessionImpl.java:1027)
在org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:304)
在org.sw.website.actions.content.AddComment.performAction( AddComment.java:60)
...

如果我需要提供更多信息请求问。一切工作,直到超过可怕的限制。

解决方案

感谢所有帮助的非sequitor。我有这个工作,我会把所有的作品放在这里供将来参考。不管所有关于升级驱动程序的声明和一切都会起作用,其中没有一个对我有用。最后,我必须实现一个'org.hibernate.usertype.UserType',我将它命名为与StringClobType上的所有示例相同。除了一些导入之外,我使用将Clobs / Blob与Oracle和Hibernate一起使用中的示例。就我而言,无视提防声明。

为了让合并工作,我必须做出一个改变。在提供的代码示例中没有实现某些方法。 Eclipse通过将它们剔除而为我修复了它。很酷,但替换方法需要实际实现,或者所有合并都会用null覆盖数据。这里是我的实现:

  public Object replace(Object newValue,Object existingValue,Object arg2)throws HibernateException {
return NEWVALUE;
}

我不会在这里复制类的实现去上面的链接看看它。我在第三个灰色框中使用了代码。然后在POJO类的顶部,我想用它在导入后添加以下内容:

$ p $ ...
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.annotations.TypeDef;

@TypeDefs({
@TypeDef(
name =clob,
typeClass = foo.StringClobType.class

} )
@Entity
@Table(name =EA_COMMENTS)
public class注释extends SWDataObject implements JSONString,Serializable {
...
}

然后,使用新的UserType,我将注释添加到我的getter中:

  @Type(type =clob)
@Column(name =COMMENT_DOC)
public String getDocument(){
return获得( 文档);
}

我不需要@Lob注解。

在我的persistence.xml中,持久化单元声明结束如下:交易类型= RESOURCE_LOCAL >
< provider> org.hibernate.ejb.HibernatePersistence< / provider>
<属性>
< property name =hibernate.archive.autodetectionvalue =class/>
< property name =hibernate.connection.passwordvalue =###/>
< property name =hibernate.connection.usernamevalue =###/>
< property name =hibernate.connection.urlvalue =jdbc:oracle:thin:@ server.something.com:1521:###/>
< property name =hibernate.connection.driver_classvalue =oracle.jdbc.OracleDriver/>
< property name =hibernate.default_schemavalue =###/>
< property name =hibernate.dialectvalue =org.hibernate.dialect.Oracle9iDialect/>
< property name =hibernate.c3p0.min_sizevalue =5/>
< property name =hibernate.c3p0.max_sizevalue =100/>
< property name =hibernate.c3p0.timeoutvalue =300/>
< property name =hibernate.c3p0.max_statementsvalue =50/>
< property name =hibernate.c3p0.idle_test periodvalue =3000/>
< property name =hibernate.c3p0.idle_connection_test_periodvalue =300/>
< property name =show_sqlvalue =false/>
< property name =format_sqlvalue =false/>
< property name =use_sql_commentsvalue =false/>
< property name =hibernate.jdbc.batch_sizevalue =0/>
< / properties>
< / persistence-unit>

SetBigStringTryClob从来没有为我工作,并且不需要这个最终实现。



我的经验教训最后可能会更好地加入到战斗中来。它会为我节省三天。

I am trying to write to an Oracle clob field a value over 4000 characters. This seams to be a common issue but non of the solutions seem to work. So I pray for help from here.

Down and dirty info:
Using Oracle 9.2.0.8.0
Hibernate3 implementing pojo's with annotations
Tomcat 6.0.16
Oracle 10.2.x drivers
C3P0 connction pool provider

In my persistence.xml I have:

<persistence-unit name="DWEB" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <properties>
        <property name="hibernate.archive.autodetection" value="class"/> 
        <property name="hibernate.connection.password" value="###" />
        <property name="hibernate.connection.username" value="###" />
        <property name="hibernate.default_schema" value="schema" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
        <property name="hibernate.c3p0.min_size" value="5" />
        <property name="hibernate.c3p0.max_size" value="20" />
        <property name="hibernate.c3p0.timeout" value="300" />
        <property name="hibernate.c3p0.max_statements" value="50" />
        <property name="hibernate.c3p0.idle_test_period" value="3000" />
        <property name="show_sql" value="true" />
        <property name="format_sql" value="true" />
        <property name="use_sql_comments" value="true" />
        <property name="SetBigStringTryClob" value="true"/>
        <property name="hibernate.jdbc.batch_size" value="0"/>
        <property name="hibernate.connection.url" value="jdbc:oracle:thin:@server.ss.com:1521:DDD"/>
        <property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver"/>
    </properties>
</persistence-unit>

The getter and setter looks like:

@Lob 
@Column(name="COMMENT_DOC")
public String getDocument(){
    return get("Document");
}
public void setDocument(String s){
    put("Document",s);
}

The exception I am getting is:

SEVERE: Servlet.service() for servlet SW threw exception
java.sql.SQLException: Io exception: Software caused connection abort: socket write error
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:334)
    at oracle.jdbc.ttc7.TTC7Protocol.handleIOException(TTC7Protocol.java:3678)
    at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1999)
    at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1144)
    at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2152)
    at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:2035)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2876)
    at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:609)
    at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:46)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2275)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2688)
    at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79)
    at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
    at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
    at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:304)
    at org.sw.website.actions.content.AddComment.performAction(AddComment.java:60)
...

If I need to give more info pleas ask. Everything works until the dreaded limit is exceeded.

解决方案

Thanks to non sequitor for all the help. I have this working and figure I will put all the pieces here for future reference. Regardless of all the claims about upgrading the drivers and everything would work, non of that worked for me. In the end I had to implement a 'org.hibernate.usertype.UserType' I named it the same as all the examples on the web StringClobType. Save for some imports I used the example from Using Clobs/Blobs with Oracle and Hibernate. As far as I am concerned ignore the "beware" claim.

There was one change I had to make to get merges to work. Some of the methods were not implemented in the provided code sample. Eclipse fixed it for me by stubbing them out. Cool, but the replace method needs to be actually implemented or all merges will overwrite the data with a null. Here is my implementation:

public Object replace(Object newValue, Object existingValue, Object arg2)throws HibernateException {
    return newValue;
}

I will not duplicate the class implementation here go to the above link to see it. I used the code in the third gray box. Then at the top of the pojo class I wanted to use it in I added the following after the imports

...  
import org.hibernate.annotations.Type;  
import org.hibernate.annotations.TypeDefs;  
import org.hibernate.annotations.TypeDef;  

@TypeDefs({  
    @TypeDef(  
        name="clob",  
        typeClass = foo.StringClobType.class  
    )  
})  
@Entity  
@Table(name="EA_COMMENTS")  
public class Comment extends SWDataObject implements JSONString, Serializable {  
...  
}   

Then to use the new UserType I added the annotation to my getter:

@Type(type="clob")
@Column(name="COMMENT_DOC")
public String getDocument(){
    return get("Document");
}

I did not need the @Lob annotation.
In my persistence.xml the persistence-unit declaration ended looking like:

<persistence-unit name="###" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <properties>
        <property name="hibernate.archive.autodetection" value="class"/> 
        <property name="hibernate.connection.password" value="###" />
        <property name="hibernate.connection.username" value="###" />
        <property name="hibernate.connection.url" value="jdbc:oracle:thin:@server.something.com:1521:###"/>
        <property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver"/>
        <property name="hibernate.default_schema" value="###" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9iDialect" />
        <property name="hibernate.c3p0.min_size" value="5" />
        <property name="hibernate.c3p0.max_size" value="100" />
        <property name="hibernate.c3p0.timeout" value="300" />
        <property name="hibernate.c3p0.max_statements" value="50" />
        <property name="hibernate.c3p0.idle_test period" value="3000" />
        <property name="hibernate.c3p0.idle_connection_test_period" value="300" />
        <property name="show_sql" value="false" />
        <property name="format_sql" value="false" />
        <property name="use_sql_comments" value="false" />
        <property name="hibernate.jdbc.batch_size" value="0"/>
    </properties>
</persistence-unit>

The SetBigStringTryClob never worked for me and was not needed for this final implementation.

My lesson learned is in the end it is probably better to join then to fight. It would of saved me three days.

这篇关于休眠&gt; CLOB&gt; Oracle :(的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆