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>