Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
3.2.5 GA
AuditTrail.hbm.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.audit" schema="g3_security">
<class name="AuditTrail" table="audit_trail">
<id name="id" column="audit_trail_id" length="10">
<generator class="native"/>
</id>
<property
name="function"
column="function"
not-null="true"
/>
<property
name="attribute"
column="attribute"
not-null="true"
/>
<property
name="oldValue"
column="old_value"
/>
<property
name="newValue"
column="new_value"
not-null="true"
/>
<property
name="createBy"
column="create_by"
not-null="true"
/>
<property
name="createOn"
type="timestamp"
update="false"
insert="false"
generated="insert"
column="create_time"
access="field"
/>
<property name="note"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
getHibernateTemplate().save(AuditTrail.class);
Full stack trace of any exception that occurs:Oracle 10g express edition. The generated SQL (show_sql=true):Debug level Hibernate log excerpt:Code:
2008-04-04 06:42:34,401 DEBUG [org.hibernate.SQL][]
insert
into
g3_security.audit_trail
(function, attribute, old_value, new_value, create_by, note, audit_trail_id)
values
(?, ?, ?, ?, ?, ?, ?)
2008-04-04 06:42:34,401 DEBUG [org.hibernate.jdbc.AbstractBatcher][] preparing statement
2008-04-04 06:42:34,401 DEBUG [org.hibernate.persister.entity.AbstractEntityPersister][] Dehydrating entity: [com.audit.AuditTrail#9673]
2008-04-04 06:42:34,401 DEBUG [org.hibernate.type.StringType][] binding 'acegi' to parameter: 1
2008-04-04 06:42:34,401 DEBUG [org.hibernate.type.StringType][] binding 'modifyBy' to parameter: 2
2008-04-04 06:42:34,401 DEBUG [org.hibernate.type.StringType][] binding 'oldValue' to parameter: 3
2008-04-04 06:42:34,401 DEBUG [org.hibernate.type.StringType][] binding 'newValue' to parameter: 4
2008-04-04 06:42:34,401 DEBUG [org.hibernate.type.StringType][] binding 'user' to parameter: 5
2008-04-04 06:42:34,401 DEBUG [org.hibernate.type.StringType][] binding null to parameter: 6
2008-04-04 06:42:34,401 DEBUG [org.hibernate.type.IntegerType][] binding '9673' to parameter: 7
2008-04-04 06:42:34,401 DEBUG [org.hibernate.jdbc.AbstractBatcher][] Executing batch size: 1
2008-04-04 06:42:34,401 DEBUG [org.hibernate.jdbc.Expectations][] success of batch update unknown: 0
2008-04-04 06:42:34,401 DEBUG [org.hibernate.jdbc.AbstractBatcher][] about to close PreparedStatement (open PreparedStatements: 1, globally: 5)
2008-04-04 06:42:34,416 DEBUG [org.hibernate.jdbc.AbstractBatcher][] closing statement
2008-04-04 06:42:34,416 DEBUG [org.hibernate.jdbc.AbstractBatcher][] about to open PreparedStatement (open PreparedStatements: 0, globally: 4)
2008-04-04 06:42:34,416 DEBUG [org.hibernate.SQL][]
select
audittrail_.create_time as create7_2_
from
g3_security.audit_trail audittrail_
where
audittrail_.audit_trail_id=?
2008-04-04 06:42:34,416 DEBUG [org.hibernate.jdbc.AbstractBatcher][] preparing statement
2008-04-04 06:42:34,416 DEBUG [org.hibernate.type.IntegerType][] binding '9673' to parameter: 1
2008-04-04 06:42:34,416 DEBUG [org.hibernate.jdbc.AbstractBatcher][] about to open ResultSet (open ResultSets: 0, globally: 0)
2008-04-04 06:42:34,416 DEBUG [org.hibernate.type.TimestampType][] returning '2008-04-04 06:42:34' as column: create7_2_
2008-04-04 06:42:34,416 DEBUG [org.hibernate.jdbc.AbstractBatcher][] about to close ResultSet (open ResultSets: 1, globally: 1)
2008-04-04 06:42:34,416 DEBUG [org.hibernate.jdbc.ConnectionManager][] registering flush end
2008-04-04 06:42:34,416 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener][] post flush
2008-04-04 06:42:34,416 DEBUG [org.hibernate.jdbc.AbstractBatcher][] about to open PreparedStatement (open PreparedStatements: 1, globally: 5)
2008-04-04 06:42:34,432 DEBUG [org.hibernate.SQL][]
The createOn field is not being persisted. For some reason it doesn't set it.