-->
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.  [ 10 posts ] 
Author Message
 Post subject: can't use Session.find.. need help
PostPosted: Tue May 30, 2006 11:03 am 
Newbie

Joined: Tue May 30, 2006 10:45 am
Posts: 7
My application don't recognize the find method of the hibernate Session class. I have specified these imports:

import java.io.IOException;
import java.util.*;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

Hibernate version:3.1

Code :
SessionFactory sessionFactory = new Configuration().configure().
buildSessionFactory();
Session newSession = sessionFactory.openSession();
Transaction tx = newSession.beginTransaction();
List messages = newSession.find("from Message as m order by m.text asc");

System.out.println(messages.size() + "message(s) found");
for(Iterator iter = messages.iterator(); iter.hasNext();)
{
Message message = (Message)iter.next();
System.out.println(message.getText());
}
tx.commit();


Full stack trace of any exception that occurs: "Message.java": cannot find symbol; symbol : method find(java.lang.String), location: interface org.hibernate.Session at line 88, column 39


Name and version of the database you are using: MS SQLSERVER 2005

Maybe somebody knows why I can't use the find method.. I can't also use the session.load method. What am I doing wrong?
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 30, 2006 11:12 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
I'm pretty sure find isn't a method that's available from the Session interface.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 30, 2006 11:18 am 
Newbie

Joined: Tue May 30, 2006 10:45 am
Posts: 7
I know the find method exists in version 2.1 in the Session interface but I'm using 3.1.. maybe the method is deprecated but I dont see what to use instead to get something that will do something like :
List messages = newSession.find("from Message as m order by m.text asc");
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 30, 2006 11:45 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
in 3.1 you need to create a query.

Query query = session.createQuery("from Message as m order by m.text asc");
List messages = query.list();

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 30, 2006 12:05 pm 
Newbie

Joined: Tue May 30, 2006 10:45 am
Posts: 7
I used the query thing you just send me like this to get all of the messages from the data base..
public static void main( String args[] )
{
try
{
SessionFactory sessionFactory = new Configuration().configure().
buildSessionFactory();
Session session = sessionFactory.openSession();
Query query = session.createQuery("from Message as m order by m.text asc");
List messages = query.list();
for(Iterator i = messages.iterator(); i.hasNext();)
{
Message message = (Message)i.next();
System.out.println(message.getText());
}
session.flush();
session.close();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
and I get this error --
java.lang.NoClassDefFoundError: antlr/ANTLRException

at org.hibernate.hql.ast.ASTQueryTranslatorFactory.createQueryTranslator(ASTQueryTranslatorFactory.java:35)

at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:72)

at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54)

at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)

at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)

at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)

at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1583)

at hello.Message.main(Message.java:97)

Exception in thread "main"

I included these
import java.io.IOException;
import java.util.*;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.Query;

Thanks a lot


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 30, 2006 12:20 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
looks like you are missing the antlr jar file from your classpath

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 30, 2006 1:44 pm 
Newbie

Joined: Tue May 30, 2006 10:45 am
Posts: 7
sorry for the questions, I'm quite new with Hibernate..

I was effectively missing antlr from my classpath but now I've got another problem.

I want to get all of the messages entries in my data base ans tought I had to do like this.
Transaction tx = session.beginTransaction();
Query query = session.createQuery("from Message as m order by m.text asc");
List messages = query.list();
System.out.println(messages.size()+"message(s)");
for(Iterator i = messages.iterator(); i.hasNext();)
{
Message message = (Message)i.next();
System.out.println(message.getText());
}
tx.commit

It doesn't return me the messages but the query itself
select message0_.MESSAGE_ID as MESSAGE1_0_, message0_.MESSAGE_TEXT as MESSAGE2_0_, message0_.NEXT_MESSAGE_ID as NEXT3_0_ from MESSAGES message0_ order by message0_.MESSAGE_TEXT asc

How do I do to get the entries ?
Thanks :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 30, 2006 2:02 pm 
Newbie

Joined: Tue May 30, 2006 10:45 am
Posts: 7
In fact I don't step into the for even if there is a record in my table messages.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 30, 2006 2:12 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
find() is still available in 3x, but it has been moved to the org.hibernate.classic.Session interface, which extends org.hibernate.Session (the signature for SessionFactory.openSession() etc is actually returning a "classic" session).

As for your last posts, I have no idea what you are saying. Are you saying that query.list() somehow returns you the string "select message0_.MESSAGE_ID as MESSAGE1_0_, message0_.MESSAGE_TEXT as MESSAGE2_0_, message0_.NEXT_MESSAGE_ID as NEXT3_0_ from MESSAGES message0_ order by message0_.MESSAGE_TEXT asc"? I find that *hard* to believe.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 30, 2006 7:20 pm 
Newbie

Joined: Tue May 30, 2006 10:45 am
Posts: 7
everything is ok
i had a property set to create in my configuration file
i wrote update instead thanks a lot


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