-->
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.  [ 8 posts ] 
Author Message
 Post subject: org.hibernate.QueryException:
PostPosted: Wed Mar 30, 2005 12:22 pm 
Newbie

Joined: Wed Mar 30, 2005 12:09 pm
Posts: 10
Hi
I am trying to retrieve data from the database and I have tried almost every kind of query but I am still getting the following error:



org.hibernate.QueryException: in expected: msg [from Message msg order by msg.text asc]
at org.hibernate.hql.classic.FromParser.token(FromParser.java:106)
at org.hibernate.hql.classic.ClauseParser.token(ClauseParser.java:86)
at org.hibernate.hql.classic.PreprocessingParser.token(PreprocessingParser.java:108)
at org.hibernate.hql.classic.ParserHelper.parse(ParserHelper.java:29)
at org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:172)
at org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:148)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:410)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:987)
at org.hibernate.impl.SessionImpl.iterate(SessionImpl.java:1018)
at org.hibernate.impl.QueryImpl.iterate(QueryImpl.java:41)
at com.webmd.bna.hello.ReadMessage.main(ReadMessage.java:41)



My ReadMessage.java looks something like the following :


import java.util.Iterator;
import java.util.List;

import org.hibernate.HibernateException;


import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
//import org.hibernate.Session;
import org.hibernate.classic.Session;
public class ReadMessage {

private static SessionFactory sessionFactory;
public static void main(String[] args) {
try {
Configuration cfg = new Configuration();
sessionFactory = cfg.buildSessionFactory();
Session session = sessionFactory.openSession();
try {
Transaction tx = session.beginTransaction();
//List messages = session.createQuery("from Message msg").list();
Query query = session.createQuery("from Message msg order by msg.text asc");

//System.out.println(messages.size() + " message(s) found");
//Query sqlQuery = session.("select {msg.*} from Message {msg}", "msg", Message.class);
Iterator itr = query.iterate();
while(itr.hasNext()) {
Message message = (Message)itr.next();
System.out.println(message.getText());
}
tx.commit();
session.close(); }
catch(HibernateException hEx) {
hEx.printStackTrace();
}
}
catch(Throwable ex) {
ex.printStackTrace(System.out);
}

}
}

I am using hibernate version 3.0.
I am using JDBC to connect to the database Version Oracle9i Enterprise Edition Release 9.2.0.1.0

Please let me know what am I doing wrong. I am using this inside the eclipse. I have the book as well as I have gone online to read and find whatever I can about HQL, but definitely I am still missing something becuase of which I am getting this exception. My mapping document looks something like this:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.webmd.bna.hello.Message" table="AC_MESSAGES">
<id name="id" column="MESSAGE_ID" type="long" unsaved-value="null">
<generator class="increment"/>
</id>
<property name="text" column="MESSAGE_TEXT" type = "string" length="100" not-null="true"/>
<many-to-one name="nextMessage" class="com.webmd.bna.hello.Message" cascade="all" column="NEXT_MESSAGE_ID"/>
</class>
</hibernate-mapping>

[/i]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 30, 2005 1:09 pm 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Hi,

When you execute the following:
Code:

Configuration cfg = new Configuration();
sessionFactory = cfg.buildSessionFactory();

... are you getting output that the class Message is being mapped using the hbm.xml file?
Your query looks good (the non-commented one):
Code:
Query query = session.createQuery("from Message msg order by msg.text asc");


I'm just wondering whether you have a configuration issue[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 30, 2005 1:29 pm 
Newbie

Joined: Wed Mar 30, 2005 12:09 pm
Posts: 10
It might be the problem with configuration but I don't know that. I am getting the following messages along with the exceptions message

11:25:24,701 INFO Environment:447 - Hibernate 3.0 beta 2
11:25:24,717 INFO Environment:465 - loaded properties from resource hibernate.properties: {hibernate.connection.username=cr_appsrvr, hibernate.connection.password=appsrvr, hibernate.cglib.use_reflection_optimizer=true, hibernate.dialect=org.hibernate.dialect.OracleDialect, hibernate.connection.url=jdbc:oracle:thin:@10.130.30.37:10920:widev, hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver}
11:25:24,717 INFO Environment:493 - using CGLIB reflection optimizer
11:25:24,732 INFO Environment:523 - using JDK 1.4 java.sql.Timestamp handling
11:25:24,732 INFO Configuration:821 - processing extends queue
11:25:24,732 INFO Configuration:825 - processing collection mappings
11:25:24,732 INFO Configuration:834 - processing association property references
11:25:24,732 INFO Configuration:861 - processing foreign key constraints
11:25:24,764 INFO Dialect:86 - Using dialect: org.hibernate.dialect.OracleDialect
11:25:24,873 INFO SettingsFactory:92 - Generate SQL with comments: disabled
11:25:24,873 INFO SettingsFactory:96 - Order SQL updates by primary key: disabled
11:25:24,873 INFO SettingsFactory:264 - Query translator: org.hibernate.hql.classic.ClassicQueryTranslatorFactory
11:25:24,889 INFO SettingsFactory:104 - Query language substitutions: {}
11:25:24,889 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
11:25:24,889 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 20
11:25:24,889 INFO DriverManagerConnectionProvider:45 - autocommit mode: false
11:25:25,014 INFO DriverManagerConnectionProvider:80 - using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@10.130.30.37:10920:widev
11:25:25,014 INFO DriverManagerConnectionProvider:86 - connection properties: {user=cr_appsrvr, password=****}
11:25:25,670 INFO SettingsFactory:145 - JDBC batch size: 15
11:25:25,670 INFO SettingsFactory:148 - JDBC batch updates for versioned data: disabled
11:25:25,670 INFO SettingsFactory:153 - Scrollable result sets: enabled
11:25:25,670 INFO SettingsFactory:161 - JDBC3 getGeneratedKeys(): disabled
11:25:25,686 INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
11:25:25,686 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
11:25:25,686 INFO SettingsFactory:173 - Automatic flush during beforeCompletion(): disabled
11:25:25,686 INFO SettingsFactory:176 - Automatic session close at end of transaction: disabled
11:25:25,686 INFO SettingsFactory:251 - Cache provider: org.hibernate.cache.EhCacheProvider
11:25:25,686 INFO SettingsFactory:184 - Second-level cache: enabled
11:25:25,686 INFO SettingsFactory:186 - Optimize cache for minimal puts: disabled
11:25:25,701 INFO SettingsFactory:194 - Structured second-level cache entries: enabled
11:25:25,701 INFO SettingsFactory:198 - Query cache: disabled
11:25:25,701 INFO SettingsFactory:209 - Statistics: disabled
11:25:25,701 INFO SettingsFactory:213 - Deleted entity synthetic identifier rollback: disabled
11:25:25,936 INFO SessionFactoryImpl:137 - building session factory
11:25:26,217 WARN Configurator:126 - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/BnaSwitch/lib/third-party/hibernate/ehcache-1.1.jar!/ehcache-failsafe.xml
11:25:26,279 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
11:25:26,279 INFO SessionFactoryImpl:363 - Checking 0 named queries
org.hibernate.QueryException: in expected: msg [from Message msg order by msg.text asc]
at org.hibernate.hql.classic.FromParser.token(FromParser.java:106)
at org.hibernate.hql.classic.ClauseParser.token(ClauseParser.java:86)
at org.hibernate.hql.classic.PreprocessingParser.token(PreprocessingParser.java:108)
at org.hibernate.hql.classic.ParserHelper.parse(ParserHelper.java:29)
at org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:172)
at org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:148)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:410)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:987)
at org.hibernate.impl.SessionImpl.iterate(SessionImpl.java:1018)
at org.hibernate.impl.QueryImpl.iterate(QueryImpl.java:41)
at com.webmd.bna.hello.ReadMessage.main(ReadMessage.java:42)


I tried looking for help on Google. Somebody was getting the similar exception and they said that when they added Message (or their class ) to the configuration, then the error was gone and everything ran successfully. So, I am not sure what to do becuase from the messages I see when I create configuration object it is able to find hibernate.properties successfully and my Message.hbm.xml mapping document is in the same directory..
Thanx for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 30, 2005 1:43 pm 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Yes - you can programmatically configure the session factory - I would suggest however that you use the XML file for configuration as a start. All your config would be in one place and it would require minimal rework. Make sure it is in the root of your classpath as per the docs.

Check out the chapter on session factory configuration (chapter 3 in the 2.1 docs) esp section 3.8, XML configuration file.


Top
 Profile  
 
 Post subject: Yes I was missing the mapping file
PostPosted: Thu Mar 31, 2005 11:59 am 
Newbie

Joined: Wed Mar 30, 2005 12:09 pm
Posts: 10
Hi,
Thanx for your help. Yes I didn't add the mapping file to the configuration file. Once I added the following statement
cfg.addResource("Message.hbm.xml")
I started getting the results. Though I am still getting some exception error but I am able to retrieve data from the database.

15:08:36,176 WARN Configurator:126 - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/BnaSwitch/lib/third-party/hibernate/ehcache-1.1.jar!/ehcache-failsafe.xml
15:08:36,457 INFO ReflectHelper:196 - reflection optimizer disabled for: com.webmd.bna.hello.Message, IllegalArgumentException: Cannot find matching method/constructor
15:08:36,535 ERROR BasicLazyInitializer:85 - CGLIB Enhancement failed: com.webmd.bna.hello.Message
java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
at net.sf.cglib.proxy.Enhancer.emitConstructors(Enhancer.java:783)
at net.sf.cglib.proxy.Enhancer.emit(Enhancer.java:749)
at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:481)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:215)
at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:368)
at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:280)
at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:597)
at org.hibernate.proxy.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:76)
at org.hibernate.proxy.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:38)
at org.hibernate.persister.AbstractEntityPersister.<init>(AbstractEntityPersister.java:458)
at org.hibernate.persister.BasicEntityPersister.<init>(BasicEntityPersister.java:352)
at org.hibernate.persister.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:95)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:44)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:196)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1031)
at com.webmd.bna.hello.ReadMessage.main(ReadMessage.java:35)
15:08:36,535 WARN AbstractEntityPersister:465 - could not create proxy class for:com.webmd.bna.hello.Message
org.hibernate.HibernateException: CGLIB Enhancement failed: com.webmd.bna.hello.Message
at org.hibernate.proxy.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:90)
at org.hibernate.proxy.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:38)
at org.hibernate.persister.AbstractEntityPersister.<init>(AbstractEntityPersister.java:458)
at org.hibernate.persister.BasicEntityPersister.<init>(BasicEntityPersister.java:352)
at org.hibernate.persister.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:95)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:44)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:196)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1031)
at com.webmd.bna.hello.ReadMessage.main(ReadMessage.java:35)
Caused by: java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
at net.sf.cglib.proxy.Enhancer.emitConstructors(Enhancer.java:783)
at net.sf.cglib.proxy.Enhancer.emit(Enhancer.java:749)
at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:481)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:215)
at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:368)
at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:280)
at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:597)
at org.hibernate.proxy.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:76)
... 8 more
15:08:36,644 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
15:08:36,644 INFO SessionFactoryImpl:363 - Checking 0 named queries


Anyway thank you very much. You guys are doing a wonderful job and are really very helpful..
Regards


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 31, 2005 12:39 pm 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Do you have a no-arg constructor in the class com.webmd.bna.hello.Message ?

i.e.
Code:
public Message() {
    super();
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 31, 2005 12:50 pm 
Newbie

Joined: Wed Mar 30, 2005 12:09 pm
Posts: 10
Actually my message class doesn't have any superclass so there is no reason for me to add
public Message() {
super();
}
Thanx


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 11, 2005 3:31 am 
Newbie

Joined: Sun Sep 11, 2005 3:28 am
Posts: 8
I get the "Superclass has no null constructors but no arguments were given" error too.

The only way I've found to avoid it is by changing the no-arg constructor visibility to protected / public.


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