File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes  org hibernate exception GenericJDBCException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark " org hibernate exception GenericJDBCException " Watch " org hibernate exception GenericJDBCException " New topic

org hibernate exception GenericJDBCException

vikram sisodia

Joined: Jul 27, 2006
Posts: 7
Hi all,
i am using hibernate 3.1 + MsSQl server 2000

1)i am write this method:

public User getUser(Integer userId) throws VdnsException{
User user = null;
Session session = null;
session = HibernateSessionFactory.getSession();
Transaction tx = session.beginTransaction();
try {
user = (User)session.get(User.class, userId);
} catch (Exception e) {
if (tx!=null) tx.rollback();
throw new VdnsException(e);
}finally {
return user;
2)hbm file :

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
Mapping file autogenerated by MyEclipse - Hibernate Tools
<class name="" table="user">
<id name="userId" type="java.lang.Integer">
<column name="userId" length="50" />
<generator class="native" />
<property name="password" type="java.lang.String">
<column name="password" length="50" not-null="true" />
<property name="id" type="java.lang.Integer">
<column name="id" />

I am not able able to get Object of user based on userId.
and finding this Exception
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not load an entity: []
Caused by: org.hibernate.exception.GenericJDBCException: could not load an entity: []
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(
at org.hibernate.exception.SQLStateConverter.convert(
at org.hibernate.exception.JDBCExceptionHelper.convert(
at org.hibernate.loader.Loader.loadEntity(
at org.hibernate.loader.entity.AbstractEntityLoader.load(
at org.hibernate.loader.entity.AbstractEntityLoader.load(
at org.hibernate.persister.entity.AbstractEntityPersister.load(
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(
at org.hibernate.event.def.DefaultLoadEventListener.load(
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(
at org.hibernate.impl.SessionImpl.fireLoad(
at org.hibernate.impl.SessionImpl.get(
at org.hibernate.impl.SessionImpl.get(
... 1 more
Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Incorrect syntax near the keyword 'user'.
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(
at org.hibernate.loader.Loader.getResultSet(
at org.hibernate.loader.Loader.doQuery(
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(
at org.hibernate.loader.Loader.loadEntity(
... 13 more

Please help me
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

"user" is a database keyword in SQL Server. The only way to access it is by escaping the keyword i.e. "select * from [user]". I don't know is Hibernate MSSQL dialect escapes keywords, but my guess is it doesn't (since the MSSQL documentation does recommand not using database keywords for object names). I'd rename the table.

One other thing - why are you performing a get within a transaction? That is just unnecessary, since you are not updating the data.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
GeeCON Prague 2014
subject: org hibernate exception GenericJDBCException