posts - 22, comments - 17, trackbacks - 0, articles - 15
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          spring+ibatis (MySql)操作clob blob

          Posted on 2012-07-18 14:45 碼農cz 閱讀(1273) 評論(0)  編輯  收藏
          spring+ ibatis 插入clob blob時
          在網上找了幾個例子,有點好用,有的報錯
          報錯如下:
          1.Spring transaction synchronization needs to be active for setting values in iBATIS TypeHandlers that delegate to a Spring LobHandler

          2. Cause: java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed

          大體就這兩個
          總的說來,就是因為事務的配置問題.
           1<!-- 事務管理 -->
           2    <bean id="transactionManager2" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
           3        <property name="dataSource" ref="dataSource"></property>
           4    </bean>
           5
           6    <!-- 聲明式事務管理 -->
           7    <bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
           8          abstract="true">
           9        <property name="transactionManager" ref="transactionManager2"></property>
          10        <property name="transactionAttributes">
          11            <props>
          12                <prop key="add*">PROPAGATION_REQUIRED</prop>
          13                <prop key="edit*">PROPAGATION_REQUIRED</prop>
          14                <prop key="*">readOnly</prop>
          15            </props>
          16        </property>
          17    </bean>
          18
          19    <bean id="sqlMapClient2"
          20          class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
          21        <property name="dataSource">
          22            <ref local="dataSource"/>
          23        </property>
          24        <property name="configLocation">
          25            <value>classpath:SqlMapConfig.xml</value>
          26        </property>
          27    </bean>
          注意:第14行
          如果,你的添加或更新操作不在add*和edit*的范圍內,而你又采用了倒霉的14行配置的時候,你的麻煩就來了......
          解決方法有很多,刪掉啊,換成PROPAGETION_REQUIRED啊都可以....推薦第二種吧....

          1 <bean id="foodService" parent="baseTransactionProxy">
          2        <property name="target">
          3            <bean class="com.bigcblob.impl.FoodServiceImpl">
          4                <property ref="foodDao" name="foodDAO"/>
          5            </bean>
          6        </property>
          7    </bean>

          你的服務類如此配置....
          額....不管你惡心沒惡心,反正我是惡心了.


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 嫩江县| 南通市| 南溪县| 南投县| 苏尼特右旗| 林周县| 顺昌县| 石柱| 宁都县| 陕西省| 平阳县| 华安县| 昌乐县| 阳新县| 鲁山县| 溆浦县| 华容县| 古丈县| 竹山县| 铜山县| 延吉市| 吉水县| 磴口县| 赫章县| 漳浦县| 安国市| 忻城县| 锡林郭勒盟| 屏东县| 郁南县| 淮北市| 剑河县| 山西省| 龙口市| 拉孜县| 宽城| 克东县| 黑河市| 长丰县| 邵武市| 抚州市|