-->
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.  [ 6 posts ] 
Author Message
 Post subject: Full Package + Class name in Query
PostPosted: Thu May 06, 2004 4:22 pm 
Beginner
Beginner

Joined: Thu May 06, 2004 4:06 pm
Posts: 25
Hello,

I am not quite a newbie, but the question sounds like it!

When querying, is there a way to use the class name only, rather than the fully qualified package name + class to reference an object? I would assume so since the Cat example in the documentation use:

Code:
List cats = sess.find(
    "from Cat as cat where cat.birthdate = ?",
    date,
    Hibernate.DATE
);


instead of

Code:
List cats = sess.find(
    "from net.sf.hibernate.examples.quickstart.Cat as cat where cat.birthdate = ?",
    date,
    Hibernate.DATE
);


since the Cat is in net.sf.hibernate.examples.quickstart package


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 4:37 pm 
Senior
Senior

Joined: Wed Mar 24, 2004 11:40 am
Posts: 146
Location: Indianapolis, IN, USA
i don't think i have ever used the full package name. i don't see why you can't use the POJO name.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 4:41 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Read documentation, <class ... auto-import="...">

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 4:46 pm 
Beginner
Beginner

Joined: Thu May 06, 2004 4:06 pm
Posts: 25
Thanks for the response. If I do not use the package name + class, I get an exception:

This works fine:

Code:
dbSession.find( "FROM com.mypackage.MyObject mo WHERE mo.name='test'" )


This does Not Work:

Code:
dbSession.find( "FROM MyObject mo WHERE mo.name='test'" )


with this exception:

Code:
net.sf.hibernate.QueryException: in expected: mo [FROM MyObject mo WHERE mo.name='test']
        at net.sf.hibernate.hql.FromParser.token(FromParser.java:102)
        at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
        at net.sf.hibernate.hql.PreprocessingParser.token(PreprocessingParser.java:123)
        at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)
        at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149)
        at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)
        at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:293)
        at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1554)
        at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1525)
        at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1513)
        at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1505)


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 5:05 pm 
Beginner
Beginner

Joined: Thu May 06, 2004 4:06 pm
Posts: 25
Quote:
Read documentation, <class ... auto-import="...">


Thanks. Had auto-import="false" on.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 5:13 pm 
Senior
Senior

Joined: Wed Mar 24, 2004 11:40 am
Posts: 146
Location: Indianapolis, IN, USA
since i use XDoclets to generate my mapping files i guess i never set the auto-import property. must default to true.


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