spring - Hibernate, properties changes not tracked -
i'am writting web application spring webflow 2.4 , hibernate 4.3. have problem changes made on entities after calling persist(). changes not tracked , calling saveorupdate before end of flow doesn't (and should useless anyway).
hib config
<bean id="oracledatasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource"> <property name="driverclassname" value="oracle.jdbc.driver.oracledriver" /> <property name="url" value="${db.oracle.url}" /> <property name="username" value="${db.oracle.user}" /> <property name="password" value="${db.oracle.password}" /> </bean> <bean id="oraclesessionfactory" class="org.springframework.orm.hibernate4.localsessionfactorybean"> <property name="datasource" ref="oracledatasource" /> <property name="entityinterceptor"> <bean class="be.core.dao.interceptor.auditinterceptor"/> </property> <property name="hibernateproperties"> <value> hibernate.temp.use_jdbc_metadata_defaults=false hibernate.default_schema= hibernate.dialect=org.hibernate.dialect.oracle9dialect </value> </property> <property name="packagestoscan"> <value>domain</value> </property> </bean>
entity :
@entity @table(name = "act") @sequencegenerator(name = "act_seq", sequencename = "act_seq") public class act extends baseentity<long> { private static final long serialversionuid = -731258565201165908l; @id @generatedvalue(strategy=generationtype.sequence, generator = "act_seq") @column(name="actnum") private long id; @notfound(action=notfoundaction.ignore) @manytoone(fetch=fetchtype.lazy) @joincolumn(name="socnum") private enterprise enterprise; @dateformat(pattern = "dd/mm/yyyy") @temporal(temporaltype.date) @column(name="actedate") private date date; @column(name = "acte", nullable = false, length = 12) private string actref;
code in flow controller :
public act createbaseact(enterprise enterprise, user user) { act act = new act(enterprise); act.setwho(user.getwho()); act.setsource(source); actdao.persist(act); return act; }
when calling persist(), id correctly generated using declared sequence.
at end of flow, commit executed result in error because property actref set after persist() , not tracked :
debug: org.hibernate.sql - insert act (datcre, majd, version, qui, acte, actedate, socnum, actenopg, actelng, actedrpg, actesrc, actenum) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) trace: org.hibernate.engine.jdbc.internal.jdbccoordinatorimpl - registering statement [oracle.jdbc.driver.oraclepreparedstatement@181496]trace: org.hibernate.persister.entity.abstractentitypersister - dehydrating entity: [domain.act#236871950] trace: org.hibernate.type.descriptor.sql.basicbinder - binding parameter [1] [date] - [mon aug 18 09:35:11 cest 2014] trace: org.hibernate.type.descriptor.sql.basicbinder - binding parameter [2] [date] - [mon aug 18 09:35:11 cest 2014] trace: org.hibernate.type.descriptor.sql.basicbinder - binding parameter [3] [integer] - [0] trace: org.hibernate.type.descriptor.sql.basicbinder - binding parameter [4] [varchar] - [qp] trace: org.hibernate.type.descriptor.sql.basicbinder - binding parameter [5] [varchar] - [null] trace: org.hibernate.type.descriptor.sql.basicbinder - binding parameter [6] [date] - [mon aug 18 09:35:11 cest 2014] trace: org.hibernate.type.descriptor.sql.basicbinder - binding parameter [7] [bigint] - [404371] trace: org.hibernate.type.descriptor.sql.basicbinder - binding parameter [8] [integer] - [1] trace: org.hibernate.type.descriptor.sql.basicbinder - binding parameter [9] [varchar] - [null] trace: org.hibernate.type.descriptor.sql.basicbinder - binding parameter [10] [integer] - [1] trace: org.hibernate.type.descriptor.sql.basicbinder - binding parameter [11] [varchar] - [6010] trace: org.hibernate.type.descriptor.sql.basicbinder - binding parameter [12] [bigint] - [236871950] debug: org.hibernate.engine.jdbc.spi.sqlexceptionhelper - not execute statement [n/a] java.sql.sqlexception: ora-01400: cannot insert null ("act"."acte")
some properties set further in flow execution if set property directly after persist(), it's not tracked...
i don't see m doing wrong here, entity should managed. have hint on this?
thank you.
when calling persist(), id correctly generated using declared sequence.
it not possible because have not_null constraint on acte
field.
see last line in strace. error correctly states cannot insert null ("act"."acte")
you have set value in actref
before persist()
object.
Comments
Post a Comment