首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

? Spring+Hibernate不能保留clob字段

2011-12-08 
? Spring+Hibernate不能保存clob字段我的配置如下:applicationContext.xml!--使用spring+hibernate处理or

? Spring+Hibernate不能保存clob字段
我的配置如下:
applicationContext.xml

<!--   使用spring+hibernate处理oracle   BLOB-->
<bean   id= "nativeJdbcExtractor "
class= "org.springframework.jdbc.support.nativejdbc.SimpleNativeJdbcExtractor "   />
<bean   id= "oracleLobHandler "
class= "org.springframework.jdbc.support.lob.OracleLobHandler "
lazy-init= "true ">
<property   name= "nativeJdbcExtractor ">
<ref   bean= "nativeJdbcExtractor "   />
</property>
</bean>


sessionFactory也加了这个属性
<property   name= "lobHandler ">
<ref   bean= "oracleLobHandler "   />
</property>

对应的hbm.xml里面对应的配置:
<property   name= "ggnr "   type= "org.springframework.orm.hibernate3.support.ClobStringType ">
<column   name= "GGNR "   />   <!--GGNR   表示公告的内容-->
</property>


对应的form为:private   String   ggnr;

主程序:

/*
  *   发布新公告
  */
public   boolean   addGgxx(HttpSession   session,   EditGgxxForm   editGgxxForm)   {
String   title   =   (String)   editGgxxForm.getGgzt();
String   nr   =   (String)   editGgxxForm.getGgnr();
Date   date   =   new   Date();
CgGgxx   ggxx   =   new   CgGgxx();
ggxx.setGgnr(nr);
ggxx.setGgzt(title);
ggxx.setFbr((String)   session.getAttribute( "user "));
ggxx.setFbrq(date);
return   ggxxDao.add(ggxx);
}


/**
  *   公告模块的功能实现
  *   @author   WMF
  *
  */
public   class   GgxxDao   extends   HibernateDaoSupport   {
/*
  *   发布新公告
  */
public   boolean   add(CgGgxx   ggxx)   {
try   {
this.getHibernateTemplate().save(ggxx);
this.getHibernateTemplate().flush();
return   true;
}   catch   (Exception   e)   {
e.printStackTrace();
return   false;
}
}
}

发布新公告的时候老是抛以下异常,请各位指教:
16:54:30,078   DEBUG   SessionImpl:219   -   opened   session   at   timestamp:   4837513912639488
16:54:30,078   DEBUG   DefaultSaveOrUpdateEventListener:161   -   saving   transient   instance
16:54:30,078   DEBUG   AbstractBatcher:311   -   about   to   open   PreparedStatement   (open   PreparedStatements:   0,   globally:   1)
16:54:30,078   DEBUG   ConnectionManager:415   -   opening   JDBC   connection
16:54:30,078   DEBUG   SQL:346   -   select   GGXX_SEQ.nextval   from   dual
16:54:30,093   DEBUG   AbstractBatcher:424   -   preparing   statement
16:54:30,093   DEBUG   SequenceGenerator:82   -   Sequence   identifier   generated:   98
16:54:30,093   DEBUG   AbstractBatcher:319   -   about   to   close   PreparedStatement   (open   PreparedStatements:   1,   globally:   2)
16:54:30,140   DEBUG   AbstractBatcher:470   -   closing   statement
16:54:30,140   DEBUG   AbstractSaveEventListener:106   -   generated   identifier:   98,   using   strategy:   org.hibernate.id.SequenceGenerator


16:54:30,140   DEBUG   AbstractSaveEventListener:139   -   saving   [com.wmf.hibernate.CgGgxx#98]
16:54:30,156   DEBUG   AbstractFlushingEventListener:58   -   flushing   session
16:54:30,156   DEBUG   AbstractFlushingEventListener:111   -   processing   flush-time   cascades
16:54:30,156   DEBUG   AbstractFlushingEventListener:153   -   dirty   checking   collections
16:54:30,156   DEBUG   AbstractFlushingEventListener:170   -   Flushing   entities   and   processing   referenced   collections
16:54:30,156   DEBUG   AbstractFlushingEventListener:209   -   Processing   unreferenced   collections
16:54:30,156   DEBUG   AbstractFlushingEventListener:223   -   Scheduling   collection   removes/(re)creates/updates
16:54:30,156   DEBUG   AbstractFlushingEventListener:85   -   Flushed:   1   insertions,   0   updates,   0   deletions   to   1   objects
16:54:30,156   DEBUG   AbstractFlushingEventListener:91   -   Flushed:   0   (re)creations,   0   updates,   0   removals   to   0   collections
16:54:30,156   DEBUG   Printer:83   -   listing   entities:
16:54:30,171   DEBUG   Printer:90   -   com.wmf.hibernate.CgGgxx{fbrq=2007-06-05   16:54:30,   ggnr=十多个   的,   ggxh=98,   fbr=null,   ggzt=十大高手多个   ,   xgrq=null}
16:54:30,171   DEBUG   AbstractFlushingEventListener:289   -   executing   flush
16:54:30,171   DEBUG   ConnectionManager:463   -   registering   flush   begin
16:54:30,171   DEBUG   AbstractEntityPersister:2034   -   Inserting   entity:   [com.wmf.hibernate.CgGgxx#98]
16:54:30,171   DEBUG   AbstractBatcher:311   -   about   to   open   PreparedStatement   (open   PreparedStatements:   0,   globally:   1)
16:54:30,171   DEBUG   SQL:346   -   insert   into   WMF.CG_GGXX   (GGZT,   GGNR,   FBRQ,   FBR,   XGRQ,   GGXH)   values   (?,   ?,   ?,   ?,   ?,   ?)
16:54:30,171   DEBUG   AbstractBatcher:424   -   preparing   statement
16:54:30,171   DEBUG   AbstractEntityPersister:1821   -   Dehydrating   entity:   [com.wmf.hibernate.CgGgxx#98]
16:54:30,203   DEBUG   ConnectionManager:472   -   registering   flush   end
16:54:30,203   DEBUG   SessionImpl:268   -   closing   session
16:54:30,203   DEBUG   ConnectionManager:374   -   performing   cleanup
16:54:30,203   DEBUG   ConnectionManager:435   -   releasing   JDBC   connection   [   (open   PreparedStatements:   1,   globally:   2)   (open   ResultSets:   0,   globally:   0)]
16:54:30,203   DEBUG   JDBCContext:199   -   after   transaction   completion
16:54:30,203   DEBUG   ConnectionManager:296   -   transaction   completed   on   session   with   on_close   connection   release   mode;   be   sure   to   close   the   session   to   release   JDBC   resources!
16:54:30,203   DEBUG   SessionImpl:417   -   after   transaction   completion
java.lang.IllegalStateException:   Active   Spring   transaction   synchronization   or   active   JTA   transaction   with   'jtaTransactionManager '   on   LocalSessionFactoryBean   required


at   org.springframework.orm.hibernate3.support.AbstractLobType.nullSafeSet(AbstractLobType.java:218)
at   org.hibernate.type.CustomType.nullSafeSet(CustomType.java:145)
at   org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:1826)
at   org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:1803)
at   org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2059)
at   org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2427)
at   org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:51)
at   org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at   org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at   org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
at   org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
at   org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at   org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at   org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:394)
at   org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:367)
at   org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:614)
at   com.wmf.hibernate.GgxxDao.add(GgxxDao.java:18)
at   com.wmf.struts.action.EditGgxxAction.addGgxx(EditGgxxAction.java:110)
at   com.wmf.struts.action.EditGgxxAction.execute(EditGgxxAction.java:68)




[解决办法]
你用的是oracle几哦。oracle8有问题,还有就是用最新的驱动。oracle10的驱动
[解决办法]
clob不能按常规字段插入,ggxx.setContent(Hibernate.createClob( " "));
SerializableClob sc = (SerializableClob)expoInfo.getContent();
Clob wrapclob = sc.getWrappedClob();
CLOB clob = (CLOB)wrapclob;
Writer cout = clob.getCharacterOutputStream();
cout.write(meetingForm.getContent());
cout.close();
[解决办法]
换驱动,ojdbc14

热点排行