UPDATE Entity 'by mistake'?
ulrike Jun 11, 2008 1:36 PMI've detected a curious behavior in my application.
I fetch an object from the database using
MyObject obj = entityManager.find(MyObject.class, id);
Then I change some field values.
I never merge/persist this object and I never call flush(), but the changes go to the database anyway. (Yes, I want to go these changes to the database in this case, but there are some tables I should never update and I want to prevent updating/inserting 'by mistake'.)
My EntityManager is injected via @In and calling entityManager.getFlushMode() returns AUTO. Can I change this to MANUAL for the whole application?
components.xml:
<persistence:managed-persistence-context name="entityManager" auto-create="true" persistence-unit-jndi-name="java:/myserviceEntityManagerFactory" />
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?> <!-- Persistence deployment descriptor for dev profile --> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"> <persistence-unit name="myservice"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:/myserviceDatasource</jta-data-source> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect"/> <property name="hibernate.hbm2ddl.auto" value="validate"/> <property name="hibernate.show_sql" value="true"/> <property name="hibernate.format_sql" value="true"/> <property name="jboss.entity.manager.factory.jndi.name" value="java:/myserviceEntityManagerFactory"/> <property name="hibernate.default_schema" value="psoft"/> <property name="hibernate.connection.autocommit" value="false"/> </properties> </persistence-unit> </persistence>