-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate Query Error
PostPosted: Thu Feb 09, 2006 9:57 pm 
Newbie

Joined: Wed Aug 17, 2005 10:50 am
Posts: 11
Hello All,

I am getting the following error for all the queries I am using. Pls help:

org.hibernate.util.JDBCExceptionReporter SQL Warning: 170, SQLState: 37000
JDBCException W org.hibernate.util.JDBCExceptionReporter Preparing
the statement failed: Line 1: Incorrect syntax near ')'.



this is the code:
session.createQuery("from FolderGS as fg1 where fg1.folderNumber = "+fldrNum).list();

This is query on the console:
Hibernate: select foldergs0_.folderNumber as folderNu1_, foldergs0_.clientSSN as clientSSN0_ from Folder foldergs0_ where (foldergs0_.folderNumber=1306767)

does any one has any idea? Pls help.

thank you for your time in advance.

Arun.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 8:13 am 
Beginner
Beginner

Joined: Wed Jan 25, 2006 10:16 am
Posts: 44
Location: Bangalore
I just tried your query as is.
I never got any error.
Are you sure the error is in this line and why does your where clause wrapped by brackets.

Can you just post more details on this?

_________________
Please vote if my Postings helps. :-)


Top
 Profile  
 
 Post subject: Hibernate Query Error
PostPosted: Fri Feb 10, 2006 2:11 pm 
Newbie

Joined: Wed Aug 17, 2005 10:50 am
Posts: 11
My web application does not get page cannot be displayed or something even if this error occurs. It just proceeds fine. Where ever hibernate does a "select" I get this error.


Here are the details of how my code works:

public List fldrRow(long fldrNum)
{

List result = null;
try
{

Session session = HibernateSessionFactory.currentSession();


if(session!=null)
{

System.out.println("The folderNumber from attribute is "+fldrNum);

result = session.createQuery("from FolderGS as fg1 where fg1.folderNumber = "+fldrNum).list();

}
}
catch (HibernateException e)
{
throw new RuntimeException(e.getMessage());
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
HibernateSessionFactory.closeSession();
}

if(result==null)
return null;

else
return result;
}









This is from HibernateSessionFactory.java

package ne.dds.caseControl.efi.hibernate;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

/**
* Basic Hibernate helper class, handles SessionFactory, Session and Transaction.
* <p>
* Uses a static initializer for the initial SessionFactory creation
* and holds Session and Transactions in thread local variables.
*
* This code has been re-written based on the original HibernateUtil.java, which was created by christain@hibernate.org
*
*/
public class HibernateSessionFactory {

private static Log log = LogFactory.getLog(HibernateSessionFactory.class);

private static Configuration configuration;
private static SessionFactory sessionFactory;
private static final ThreadLocal threadSession = new ThreadLocal();
private static final ThreadLocal threadTransaction = new ThreadLocal();
private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";

// Create the initial SessionFactory from [edcs.hibernate.cfg.xml] configuration file
static {
try {
configuration = new Configuration();
sessionFactory = configuration.configure(CONFIG_FILE_LOCATION).buildSessionFactory();
} catch (Throwable ex) {
// We have to catch Throwable, otherwise we will miss
// NoClassDefFoundError and other subclasses of Error
log.error("Building SessionFactory failed.", ex);
throw new ExceptionInInitializerError(ex);
}
}

/**
* Returns the SessionFactory used for this static class.
*
* @return SessionFactory
*/
public static SessionFactory getSessionFactory() {
return sessionFactory;
}

/**
* Retrieves the current Session local to the thread.
* <p/>
* If no Session is open, opens a new Session for the running thread.
*
* @return Session
*/
public static Session getSession() throws HibernateException {
try {
Session s = (Session) threadSession.get();
if (s == null) {
//log.info("Opening new Session for this thread.");
s = getSessionFactory().openSession();
threadSession.set(s);
}
return s;
}catch(HibernateException ex){
throw ex;
}
}
public static Session getNewSession() throws HibernateException {
Session s = null;
s = getSessionFactory().openSession();
return s;
}
/**
* Retrieves the current Session local to the thread.
* <p/>
* If no Session is open, opens a new Session for the running thread.
*
* @return Session
*/
public static Session currentSession() throws HibernateException {
try {
Session s = (Session) threadSession.get();

if (s == null) {
//log.info("Opening new Session for this thread.");
s = getSessionFactory().openSession();
threadSession.set(s);
}
return s;
}catch(HibernateException ex){
throw ex;
}
}

/**
* Closes the Session local to the thread.
*/
public static void closeSession() throws HibernateException {
try {
Session s = (Session) threadSession.get();
threadSession.set(null);
if (s != null && s.isOpen()) {
//log.info("Closing Session for this thread.");
s.close();
s = null;
}
}catch(HibernateException ex){
throw ex;
}
}

/**
* Closes the Session local to the thread.
*/
public static void close() throws HibernateException {
try {
Session s = (Session) threadSession.get();
threadSession.set(null);
if (s != null && s.isOpen()) {
//log.info("Closing Session for this thread.");
s.close();
s = null;
}
}catch(HibernateException ex){
throw ex;
}
}


/**
* Start a new database transaction.
*/
public static void beginTransaction() throws HibernateException {
try {
Transaction tx = (Transaction) threadTransaction.get();
if (tx == null) {
//log.info("Starting new database transaction in this thread.");
tx = getSession().beginTransaction();
threadTransaction.set(tx);
}
} catch (HibernateException ex){
throw ex;
}
}

/**
* Commit the database transaction.
*/
public static void commitTransaction() throws HibernateException {
Transaction tx = (Transaction) threadTransaction.get();
try {
if ( tx != null && !tx.wasCommitted()
&& !tx.wasRolledBack() ) {
//log.info("Committing database transaction in this thread.");
tx.commit();
}
threadTransaction.set(null);
} catch (HibernateException ex) {
rollbackTransaction();
throw ex;
}
}

/**
* Rollback the database transaction.
*/
public static void rollbackTransaction() throws HibernateException {
Transaction tx = (Transaction) threadTransaction.get();
try {
threadTransaction.set(null);
if ( tx != null && !tx.wasCommitted() && !tx.wasRolledBack() ) {
//log.info("Tyring to rollback database transaction in this thread.");
tx.rollback();
}
} catch (HibernateException ex) {
throw ex;
} finally {
closeSession();
}
}
}





This is my hibernate.cfg.xml file

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"

"C:\neb\hibernate-configuration-3.0.dtd">
<!-- D:\Mystery\TestSample\JavaSource\ -->
<hibernate-configuration>

<session-factory>
<property name="hibernate.connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:jtds:sqlserver://10.211.179.200:1433/backupcasemsbesql;TDS=4.2</property>
<!-- jdbc:jtds:sqlserver://172.31.68.130:1433/Northwind;TDS=7.0 -->
<!-- jdbc:jtds:sqlserver://172.31.68.220:1433/backupcasemsbesql;TDS=7.0 -->
<property name="hibernate.connection.username">jimw</property>
<property name="hibernate.connection.password"></property>
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="show_sql">true</property>
<property name="transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory
</property>
<property name="hibernate.cache.provider_class">
org.hibernate.cache.HashtableCacheProvider
</property>
<property name="hibernate.hbm2ddl.auto">update</property>



<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>

<property name="hibernate.cglib.use_reflection_optimizer">false</property>
<property name="hibernate.cache.use_query_cache">false</property>

<property name="hibernate.cache.use_minimal_puts">false</property>


<!-- EFI Tables -->
<mapping resource="ne/dds/caseControl/efi/mapping/Folder.hbm.xml"/>
</session-factory>

</hibernate-configuration>


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