在事务ReadOnly!
之后,不会执行持久化/插入过程我的applicationContext.xml:
<bean id="transactionManagerConstant" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="constant"/>
<property name="jpaDialect" ref="jpaDialect" />
</bean>
<bean id="constant" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitManager" ref="persistenceUnitManager" />
<property name="persistenceUnitName" value="JSFSpring" />
</bean>
Java代码:
@Transactional(isolation = Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, readOnly=false)
public String workSaved(){
em.persist(work);
work = (Work) ctx.getBean("work");
return "/list.xhtml";
}
@Transactional(propagation = Propagation.REQUIRED, readOnly=true)
public List<Odev> getWorkedList() {
return workedList = (List<Work>) em.createNamedQuery("Work.findAll").getResultList();
}
异常: javax.persistence.PersistenceException:org.hibernate.exception.GenericJDBCException:无法插入:[com.hakdogan.hakdoganjsfspring.entity.Work]
引起:java.sql.SQLException:连接是只读的。不允许导致数据修改的查询 在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073) 在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987) 在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982) 在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927) 在com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2378) 在com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2345) 在com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2330) at org.hibernate.id.IdentityGenerator $ GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:94) at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57) ......还有73个