-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Session.save -> bean sholud be persisten but is DETACHED
PostPosted: Mon Dec 19, 2005 7:55 am 
Regular
Regular

Joined: Wed Sep 22, 2004 8:27 am
Posts: 89
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 9

The 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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 27, 2005 3:26 pm 
Regular
Regular

Joined: Fri Sep 09, 2005 11:35 am
Posts: 101
may be pretty obvious but i did not see you assigning a primary key to the import bean. You have generator class as assigned in your mapping.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.