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.  [ 1 post ] 
Author Message
 Post subject: CMT/EJB problem -hibernate don't save the object to the base
PostPosted: Mon Aug 27, 2007 9:46 am 
Newbie

Joined: Mon Aug 27, 2007 8:51 am
Posts: 2
use:
Hibernate 3.2
websphere 6.1
MySql 5.0

I have the problem to commit transaction by container. I'm gonna save the pojo database by the hibernate.
the configuration file (hibernate.cfg.xml) looks like below :

Code:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<!-- Basic -->
   <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
   <property name="hibernate.connection.url">jdbc:mysql://localhost/hibernatetutorial</property>
   <property name="hibernate.connection.username">root</property>
   <property name="hibernate.connection.password">mypassword</property>
   <property name="hibernate.connection.pool_size">10</property>
   <property name="show_sql">true</property>
   <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
   <property name="hibernate.hbm2ddl.auto">update</property>

<!-- Websphere -->
  <!-- Manager Lookup -->
   <property name="hibernate.TransactionManagerLookup">org.hibernate.transaction.WebSphereTransactionManagerLookup</property>
   <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.WebSphereTransactionManagerLookup</property>
 
  <!-- Transaction Strategy -->
   <property name="hibernate.TransactionManagerLookupStrategy">org.hibernate.transaction.WebSphereTransactionManagerLookup</property>
   <property name="hibernate.TransactionStrategy">org.hibernate.transaction.CMTTransactionFactory</property>
   
  <!-- Factory class -->
    <property name="hibernate.transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</property>
   
  <!-- Other -->
   <property name="hibernate.connection.release_mode">after_statement</property>
   <property name="hibernate.transaction.auto_close_session">true</property>
   <property name="hibernate.transaction.flush_before_completion">true</property>

<!-- Mapping files -->
   <mapping resource="pl/test/hibernate/contact.hbm.xml" />
   
</session-factory>
</hibernate-configuration>


I implemented facade as a session bean with method saveMessageToDb:

Code:
public void saveMessageToDb() throws Exception  {
   
   Session session = null;
   try {
   SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
   session = sessionFactory.getCurrentSession();
           System.out.println("Inserting Record");
           Contact contact = new Contact();
           Random random = new Random();
           contact.setId(random.nextInt(10000));
           contact.setFirstName("yyyz");
           contact.setLastName("zzzz");
           contact.setEmail("xxx@www.com");
           session.save(contact);
           System.out.println("Done");
       }catch(Exception e){
         System.out.println(e.getMessage());
       }finally{
       //none
         }   
         
      }


In ejb-jar.xml, I declare to put transaction on this method:

Code:
  <container-transaction>
   <method>
    <ejb-name>DBFacade</ejb-name>
    <method-intf>Local</method-intf>
    <method-name>saveMessageToDb</method-name>
    <method-params>
    </method-params>
   </method>
   <trans-attribute>Required</trans-attribute>
  </container-transaction>




I think everything looks good. When I start server I take this log:

Quote:
[27.08.07 15:23:18:770 CEST] 00000026 SystemOut O opened session at timestamp: 11882209987
[27.08.07 15:23:18:770 CEST] 00000026 SystemOut O Inserting Record
[27.08.07 15:23:18:770 CEST] 00000026 SystemOut O saving transient instance
[27.08.07 15:23:18:770 CEST] 00000026 SystemOut O generated identifier: 5526, using strategy: org.hibernate.id.Assigned
[27.08.07 15:23:18:785 CEST] 00000026 SystemOut O saving [pl.pbpolsoft.test.hibernate.Contact#5526]
[27.08.07 15:23:18:785 CEST] 00000026 SystemOut O Done
[27.08.07 15:23:18:785 CEST] 00000026 SystemOut O >>>>stworzenie EJB - DBFacade
[27.08.07 15:23:18:785 CEST] 00000026 SystemOut O transaction before completion callback
[27.08.07 15:23:18:801 CEST] 00000026 SystemOut O automatically flushing session
[27.08.07 15:23:18:832 CEST] 00000026 SystemOut O automatically flushing session
[27.08.07 15:23:18:848 CEST] 00000026 SystemOut O flushing session
[27.08.07 15:23:18:848 CEST] 00000026 SystemOut O processing flush-time cascades
[27.08.07 15:23:18:863 CEST] 00000026 SystemOut O dirty checking collections
[27.08.07 15:23:18:879 CEST] 00000026 SystemOut O Flushing entities and processing referenced collections
[27.08.07 15:23:18:879 CEST] 00000026 SystemOut O Processing unreferenced collections
[27.08.07 15:23:18:895 CEST] 00000026 SystemOut O Scheduling collection removes/(re)creates/updates
[27.08.07 15:23:18:910 CEST] 00000026 SystemOut O Flushed: 1 insertions, 0 updates, 0 deletions to 1 objects
[27.08.07 15:23:18:926 CEST] 00000026 SystemOut O Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
[27.08.07 15:23:18:941 CEST] 00000026 SystemOut O listing entities:
[27.08.07 15:23:18:957 CEST] 00000026 SystemOut O pl.pbpolsoft.test.hibernate.Contact{email=deepak_38@yahoo.com, firstName=Deepak, id=5526, lastName=Kumar}
[27.08.07 15:23:18:973 CEST] 00000026 SystemOut O executing flush
[27.08.07 15:23:18:973 CEST] 00000026 SystemOut O registering flush begin
[27.08.07 15:23:18:988 CEST] 00000026 SystemOut O Inserting entity: [pl.pbpolsoft.test.hibernate.Contact#5526]
[27.08.07 15:23:19:004 CEST] 00000026 SystemOut O about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
[27.08.07 15:23:19:004 CEST] 00000026 SystemOut O opening JDBC connection
[27.08.07 15:23:19:020 CEST] 00000026 SystemOut O total checked-out connections: 0
[27.08.07 15:23:19:035 CEST] 00000026 SystemOut O using pooled JDBC connection, pool size: 0
[27.08.07 15:23:19:051 CEST] 00000026 SystemOut O insert into CONTACT (FIRSTNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?)
[27.08.07 15:23:19:051 CEST] 00000026 SystemOut O Hibernate: insert into CONTACT (FIRSTNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?)
[27.08.07 15:23:19:051 CEST] 00000026 SystemOut O preparing statement
[27.08.07 15:23:19:066 CEST] 00000026 SystemOut O Dehydrating entity: [pl.pbpolsoft.test.hibernate.Contact#5526]
[27.08.07 15:23:19:082 CEST] 00000026 SystemOut O binding 'Deepak' to parameter: 1
[27.08.07 15:23:19:098 CEST] 00000026 SystemOut O binding 'Kumar' to parameter: 2
[27.08.07 15:23:19:098 CEST] 00000026 SystemOut O binding 'deepak_38@yahoo.com' to parameter: 3
[27.08.07 15:23:19:113 CEST] 00000026 SystemOut O binding '5526' to parameter: 4
[27.08.07 15:23:19:129 CEST] 00000026 SystemOut O Executing batch size: 1
[27.08.07 15:23:19:145 CEST] 00000026 SystemOut O about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
[27.08.07 15:23:19:160 CEST] 00000026 SystemOut O closing statement
[27.08.07 15:23:19:160 CEST] 00000026 SystemOut O skipping aggressive-release due to flush cycle
[27.08.07 15:23:19:176 CEST] 00000026 SystemOut O registering flush end
[27.08.07 15:23:19:191 CEST] 00000026 SystemOut O aggressively releasing JDBC connection
[27.08.07 15:23:19:207 CEST] 00000026 SystemOut O releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
[27.08.07 15:23:19:207 CEST] 00000026 SystemOut O returning connection to pool, pool size: 1
[27.08.07 15:23:19:223 CEST] 00000026 SystemOut O post flush
[27.08.07 15:23:19:238 CEST] 00000026 SystemOut O before transaction completion
[27.08.07 15:23:19:254 CEST] 00000026 SystemOut O before transaction completion
[27.08.07 15:23:19:254 CEST] 00000026 SystemOut O transaction after completion callback, status: 3
[27.08.07 15:23:19:270 CEST] 00000026 SystemOut O after transaction completion
[27.08.07 15:23:19:285 CEST] 00000026 SystemOut O after transaction completion
[27.08.07 15:23:19:301 CEST] 00000026 SystemOut O automatically closing session
[27.08.07 15:23:19:316 CEST] 00000026 SystemOut O automatically closing session
[27.08.07 15:23:19:332 CEST] 00000026 SystemOut O closing session


but database table is still clear. Hibernate doesn't save my object to the datebase table.

what i should do ? did anybody forced this problem before ?


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

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.