Hi Hibernate community,
I am trying to get Hibernate to run using MS SQL Server 2000 using the ThreadLocal session handling approach (see class HiberateSession below).
(As far as I can see, this requires the usage of the file hibernate.cfg.xml instead of hibernate.properties).
But when doing so, I get the runtime error: java.lang.UnsupportedOperationException: The user must supply a JDBC connection. while the system starts up.
The connection to the SQL Server 2000 database works using hibernate.properties, otherwise.
Can you please have a look and give me a hint what I have to do to get the version tag approach for
optimistic locking up and running using SQL Server 2000 ?
Thanks for help,
Dirk V. Schesmer
Stuttgart/Germany
--- start hibernate.cfg.xml ---
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">net.avenir.jdbc3.Driver</property>
<property name="hibernate.connection.url">jdbc:AvenirDriver://127.0.0.1:1433/Northwind</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password"></property>
<property name="dialect">net.sf.hibernate.dialect.SQLServerDialect</property>
<property name="show_sql">true</property>
<property name="transaction.factory_class">
net.sf.hibernate.transaction.JDBCTransactionFactory
</property>
<property name="hibernate.cache.provider_class">
net.sf.hibernate.cache.HashtableCacheProvider
</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping resource="de/ic/sql/CD.hbm.xml"/>
</session-factory>
</hibernate-configuration>
--- end ---
--- start CD.hbm.xml ---
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="de.ic.sql.CD"
table="cd">
<id name="id"
type="int"
unsaved-value="null">
<column name="ID"
sql-type="integer"
not-null="true"/>
<generator class="native"/>
</id>
<version name="version" column="version" type="integer" unsaved-value="undefined"/>
<property name="title"/>
<property name="artist"/>
<property name="purchasedate" type="date"/>
<property name="cost" type="double"/>
</class>
</hibernate-mapping>
--- end ---
package de.ic.sql;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
public class HibernateSession {
private static final SessionFactory sessionFactory;
static {
try {
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (HibernateException e) {
throw new RuntimeException("SessionFactory Error - " + e.getMessage(), e);
}
}
public static final ThreadLocal session = new ThreadLocal();
public static Session currentSession() throws HibernateException {
Session s = (Session) session.get();
if (s == null) {
s = sessionFactory.openSession();
session.set(s);
}
return s;
}
public static void closeSession() throws HibernateException {
Session s = (Session) session.get();
session. set(null);
if (s != null)
s.close();
}
}
--- start error report ---
D:\java\projekte\part2>java -cp .;D:\hibernate-2.1\hibernate2.jar;D:\hibernate-2
.1\lib\log4j-1.2.8.jar;D:\hibernate-2.1\lib\cglib-full-2.0.2.jar;D:\hibernate-2.
1\lib\commons-collections-2.1.1.jar;D:\hibernate-2.1\lib\commons-logging-1.0.4.j
ar;D:\hibernate-2.1\lib\dom4j-1.4.jar;D:\hibernate-2.1\lib\ehcache-0.9.jar;D:\hi
bernate-2.1\lib\jdbc2_0-stdext.jar;D:\hibernate-2.1\lib\jta.jar;D:\hibernate-2.1
\lib\odmg-3.0.jar;D:\hibernate-2.1\lib\xalan-2.4.0.jar;D:\hibernate-2.1\lib\xala
n-2.4.0.jar;D:\hibernate-2.1\lib\xml-apis.jar;D:\Borland\JBuilder2005\samples\js
f\Tomcat\bookstore\WEB-INF\lib\TaveConnect30C.jar;D:\java\projekte\hibernate\cla
sses de.ic.sql.CDTestList
Exception in thread "main" java.lang.UnsupportedOperationException: The user mus
t supply a JDBC connection
at net.sf.hibernate.connection.UserSuppliedConnectionProvider.getConnect
ion(UserSuppliedConnectionProvider.java:32)
at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:286
)
at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3326)
at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3286)
at net.sf.hibernate.impl.BatcherImpl.prepareQueryStatement(BatcherImpl.j
ava:65)
at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:779)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:265)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections
(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1544)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1521)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1513)
at de.ic.sql.CDTestList.list(CDTestList.java:26)
at de.ic.sql.CDTestList.main(CDTestList.java:42)
---
--- start CD.java ---
package de.ic.sql;
import java.util.Date;
public class CD {
int id;
String title;
String artist;
Date purchaseDate;
double cost;
int version;
public CD() { }
public CD(String title, String artist, Date purchaseDate, double cost) {
this.title = title; this.artist = artist; this.purchaseDate = purchaseDate; this.cost = cost; }
public void setId(int id) { this.id = id; }
public int getId(){ return id; }
public void setTitle(String title) { this.title = title; }
public String getTitle() { return title; }
public void setArtist(String artist) { this.artist = artist; }
public String getArtist() { return artist; }
public void setPurchasedate(Date purchaseDate) { this.purchaseDate = purchaseDate; }
public Date getPurchasedate() { return purchaseDate; }
public void setCost(double cost) { this.cost = cost; }
public void setVersion(int version) { this.version = version; }
public double getCost() { return cost; }
public int getVersion() { return version; }
}
--- end ---
|