-->
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.  [ 4 posts ] 
Author Message
 Post subject: Startup exc. w/ hibernate.cfg.xml and ThreadLocal sess. hdl.
PostPosted: Sat Oct 30, 2004 3:13 pm 
Newbie

Joined: Thu Oct 28, 2004 1:33 pm
Posts: 14
Location: Stuttgart
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 ---


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 30, 2004 3:16 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
This HibernateSession class is broken (it swallows Exceptions). The rest of your code also looks like it was copied from "Professional Hibernate". Please, use the reference documentation, this book has many errors like this and can't really be recommended.

If you need free tutorials, see our Documentation page.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 30, 2004 4:55 pm 
Newbie

Joined: Thu Oct 28, 2004 1:33 pm
Posts: 14
Location: Stuttgart
Well, in addition to "Hibernate in action" I have in my office, I indeed yesterday bought "Professional Hibernate" and spend the whole day today to get the samples up and running. It started very well in the morning, but code and book turned to be so faulty over the day that I will return it next week to the local book seller. Hope "Hibernate in Action" will provide me with more solid answers to my still open questions about safe multiuser concurrent access to MS SQL Server 2000 using Hibernate !

Dirk V. Schesmer
Stuttgart/Germany


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 31, 2004 6:01 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
It would be helpful if you can post this to the respective Amazon pages as a review.

So far, the comments don't reflect reality (well, no surprise if there are only reviews without REAL NAMES from, most likely, fake accounts). Wiley (the publisher of "Professional Hibernate") deletes my reviews (I am trying to find out why and on what grounds).

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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