This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes  org hibernate exception GenericJDBCException Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply Bookmark " org hibernate exception GenericJDBCException " Watch " org hibernate exception GenericJDBCException " New topic
Author

org hibernate exception GenericJDBCException

vikram sisodia
Greenhorn

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 {
session.close();
}
return user;
}
2)hbm file :

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

I am not able able to get Object of user based on userId.
and finding this Exception
Exception in thread "main" co.jp.vdns.external.db.exception.VdnsException: org.hibernate.exception.GenericJDBCException: could not load an entity: [co.jp.bo.User#1]
at co.jp.vdns.common.test.TestObjectFetch.getUser(TestObjectFetch.java:38)
at co.jp.vdns.common.test.TestObjectFetch.main(TestObjectFetch.java:25)
Caused by: org.hibernate.exception.GenericJDBCException: could not load an entity: [co.jp.bo.User#1]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1799)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:47)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:41)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2730)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:365)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:346)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:123)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:177)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:862)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:799)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:792)
at co.jp.vdns.common.test.TestObjectFetch.getUser(TestObjectFetch.java:34)
... 1 more
Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Incorrect syntax near the keyword 'user'.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.postImplExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.executeQuery(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1785)
... 13 more

Please help me
Paul Sturrock
Bartender

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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: org hibernate exception GenericJDBCException
 
Similar Threads
Not closing pre-bound Hibernate Session after HibernateTemplate
Hibernate mapping in Spring - Getting Exception
elt column hibernate
SQL server and hibernate
SQLException: Invalid value for getInt() + scrambled columns