Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.1
Mapping documents:
Code:
<hibernate-mapping default-lazy="false">
<class name="com.coginfo.kf.bean.Import" table="KFT_IMPORT" select-before-update="true">
<meta attribute="class-description">Import</meta>
<id name="cafimp" type="string" unsaved-value="null">
<column name="cafimp" sql-type="string" not-null="true" length="30"/>
<generator class="assigned"/>
</id>
<property name="dscimp" type="string">
<column name="dscimp" length="100" sql-type="string" not-null="true"/>
</property>
<property name="sqlldrctr" type="string">
<column name="sqlldrctr" length="100" sql-type="string" not-null="false"/>
</property>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
begin();
Import bean = new Import()
...
insert(bean);
commit();
Code:
public void insert(Object data) throws HibernateException{
session.save(data);
}
public commit(){
Transaction tx = (Transaction) threadTransaction.get();
if ( tx != null && !tx.wasCommitted() && !tx.wasRolledBack() ) {
detailLog.debug("Committing database transaction of this thread.");
tx.commit();
}
threadTransaction.set(null);
}
Name and version of the database you are using: Oracle 9The generated SQL (show_sql=true):NO SQL Insert
When Hibernate execute the methos
session.save, flush, commit no insert sql is genereted.
The question is, why???? hava i to use currentSession or i can use my threadlocal var???
I try to look hibernate source of
DefaultSaveOrUpdateEventListener and i found:
event.getEntity() ---> correct is an Import bean
event.getEntry() ----> is NULL
entityState -----> is 2
Code:
protected Serializable performSaveOrUpdate(SaveOrUpdateEvent event) {
// use various roles to determine if the instance is
// transient, persistent or detached:
int entityState = getEntityState(
event.getEntity(),
event.getEntityName(),
event.getEntry(),
event.getSession()
);
switch (entityState) {
case DETACHED:
entityIsDetached(event);
return null;
case PERSISTENT:
return entityIsPersistent(event);
default: //TRANSIENT or DELETED
return entityIsTransient(event);
}
}
thanks