-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problems with session.save() in MS SQL.
PostPosted: Mon Jan 29, 2007 5:28 am 
Newbie

Joined: Thu Jan 25, 2007 10:13 am
Posts: 5
I have a problem with persisting simple objects to a MS SQL Server. My code works just fine when I am running it with MySQL. But the customer demands MsSQL.

I get no Errors when running it with MS SQL and the output is the same as when running with MySQL. It just doesn´t save it to the DB. Also, the db-table gets locked. It is not possible to access the table with an external application such as MS Query Analyzer.

Someone who have a clue.. here is the details:

Hibernate version: 3

Mapping documents:
Code:
<hibernate-mapping>
  <class name="com.icr3.model.Test">
    <id name="id" type="long" column="id">
      <generator class="native"/>
    </id>
    <property name="test"/>
  </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
public class TestManager extends AbstractManager {
    public void createTest() {
        Test t = new Test();
        t.setTest("hej och hallå");
        try {
            testDao.createTest(t);
        } finally {
            closeSession();
        }
    }
}

Code:
public class TestDAO extends AbstractDAO {
    public void createTest(Test test) {
        try {
            session().save(test);
        }
        catch (HibernateException e) {
            throw new RuntimeException(e);
        }
    }
}

Code:
public abstract class AbstractDAO {
  Logger log = Logger.getLogger(getClass().getName());

  /**
   * The simplest possible way to access the active hibernate session
   * of the current thread.
   */
  protected Session session() {
      return HibernateUtil.currentSession();
  }
}

closeSession() is implemented in AbstractManager and is making a call to :
HibernateUtil.closeSession()
Code:
public static void closeSession() {
        Session s = (Session) session.get();
        log.debug("SESSION = " + s);
        session.set(null);
        if (s != null) {
            try {
                s.flush();
                s.close();
            }
            catch (HibernateException e) {
                throw new RuntimeException(e);
            }
        }
    }


where testDao is declared in AbstractManager..

Full stack trace of any exception that occurs: No stacktrace..

Name and version of the database you are using: SQL Server Standard Edition 8.00.763(SP3). SQL server 2000

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:
2007-01-29 09:53:49,166 DEBUG [org.hibernate.impl.SessionFactoryObjectFactory] initializing class SessionFactoryObjectFactory
2007-01-29 09:53:49,166 DEBUG [org.hibernate.impl.SessionFactoryObjectFactory] registered: 8a178152106d0f5e01106d0f61ee0000 (unnamed)
2007-01-29 09:53:49,166 INFO [org.hibernate.impl.SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
2007-01-29 09:53:49,166 DEBUG [org.hibernate.impl.SessionFactoryImpl] instantiated session factory
2007-01-29 09:53:49,166 DEBUG [org.hibernate.impl.SessionFactoryImpl] Checking 0 named HQL queries
2007-01-29 09:53:49,166 DEBUG [org.hibernate.impl.SessionFactoryImpl] Checking 0 named SQL queries
2007-01-29 09:53:49,261 DEBUG [org.hibernate.impl.SessionImpl] opened session at timestamp: 11700608291
2007-01-29 09:53:49,276 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] executing identity-insert immediately
2007-01-29 09:53:49,276 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2007-01-29 09:53:49,276 DEBUG [org.hibernate.jdbc.ConnectionManager] opening JDBC connection
2007-01-29 09:53:49,276 DEBUG [org.hibernate.SQL] insert into Test (test) values (?)
2007-01-29 09:53:49,276 INFO [STDOUT] Hibernate: insert into Test (test) values (?)
2007-01-29 09:53:49,292 DEBUG [org.hibernate.id.IdentifierGeneratorFactory] Natively generated identity: 1
2007-01-29 09:53:49,292 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2007-01-29 09:53:49,308 DEBUG [com.icr3.util.HibernateUtil] SESSION = SessionImpl(PersistenceContext[entityKeys=[EntityKey[com.icr3.model.Test#1]],collectionKeys=[]];ActionQueue[insertions=[] updates=[] deletions=[] collectionCreations=[] collectionRemovals=[] collectionUpdates=[]])
2007-01-29 09:53:49,308 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] processing flush-time cascades
2007-01-29 09:53:49,308 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] dirty checking collections
2007-01-29 09:53:49,324 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] Flushed: 0 insertions, 0 updates, 0 deletions to 1 objects
2007-01-29 09:53:49,324 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
2007-01-29 09:53:49,324 DEBUG [org.hibernate.pretty.Printer] listing entities:
2007-01-29 09:53:49,324 DEBUG [org.hibernate.pretty.Printer] com.icr3.model.Test{test=hej och hallå, id=1}
2007-01-29 09:53:49,324 DEBUG [org.hibernate.jdbc.ConnectionManager] releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
2007-01-29 09:53:49,324 DEBUG [org.hibernate.jdbc.ConnectionManager] aggressively releasing JDBC connection
2007-01-29 09:53:49,340 TRACE [jbossws.SOAPMessage] Outgoing SOAPMessage
<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>
<env:Header/>
<env:Body>
<ns1:saveTestResponse xmlns:ns1='http://webservice.icr3.com/jaws'>
<result>klart och betalt</result>
</ns1:saveTestResponse>
</env:Body>
</env:Envelope>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 29, 2007 5:35 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
You forget to commit the transaction. MySql has table types without transactions.

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 29, 2007 5:58 am 
Newbie

Joined: Thu Jan 25, 2007 10:13 am
Posts: 5
Thank you so much..

As a matter of fact we were running the mysql with "myISAM". Should have figured that out, but I am kind of a newbie to Hibernate.

Again, thanks a LOT!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.