qq931399960
爱上冬日暖阳
采纳率20%
2015-04-22 08:28 阅读 1.5k

spring+hibernate注解开发异常,事务相关

异常信息:
org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
at org.springframework.orm.hibernate4.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1135)

事务配置:
<bean id="txManager"
    class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"></property>
    <property name="nestedTransactionAllowed" value="true" />

</bean>

<tx:annotation-driven transaction-manager="txManager" proxy-target-class="true"
    mode="proxy" />

    service添加了事务注解

     @Transactional
public void saveSyslogAlarm(SyslogAlarm s){
    dao.saveSyslogAlarm(s);
}

    实体类:

    @Table(name="syslogAlarm")

@Entity
public class SyslogAlarm {

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@GenericGenerator(name="generator",strategy="increment")
@Column(name="id",unique=true,nullable=false)
private int id;

@Column(name="content")
private String content;
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • sinat_16069871 sinat_16069871 2015-04-29 08:44

    “read-only”

    你的项目里面有两个相同的@Action注解类

    点赞 评论 复制链接分享

相关推荐