-->
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: Using interfaces in HQL
PostPosted: Fri Sep 24, 2004 10:27 am 
Regular
Regular

Joined: Thu Aug 28, 2003 10:54 am
Posts: 67
Hibernate version:
2.1.6

Mapping documents:
<hibernate-mapping>
<class name="com.wdb.sites.WebSiteImpl" proxy="com.wdb.sites.WebSite" table="websites">
<id name="id">
<generator class="sequence">
<param name="sequence">websites_id_seq</param>
</generator>
</id>

<property name="name" not-null="true"/>

</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Collection results = session.find("select w from WebSite w");

Full stack trace of any exception that occurs:
Exception in thread "main" net.sf.hibernate.QueryException: in expected: w [select w from WebSite w]
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.end(PreprocessingParser.java:142)
at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:30)
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:294)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1562)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1533)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1521)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1513)
at com.wdb.main.Main.main(Main.java:24)

Name and version of the database you are using:
postgresql 7.4

The generated SQL (show_sql=true):
none

Debug level Hibernate log excerpt:
2004-09-24 15:22:04,024 SessionImpl - find: select w from WebSite w
2004-09-24 15:22:04,037 QueryTranslator - compiling query
Exception in thread "main" net.sf.hibernate.QueryException: in expected: w [select w from WebSite w]

This works fine if I replace WebSite with WebSiteImpl. However, I was hoping not to use concrete classes in the HQL. Is it possible to use interfaces in HQL?

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 24, 2004 10:32 am 
Newbie

Joined: Fri Aug 27, 2004 5:36 pm
Posts: 16
Location: Pittsburgh
I think its throwing error maybe because WebSite is not mapped or not loaded. I am not sure though.

Usually i get this kinda exception if i didn't map or load the mapping.

_________________
--------------------------------------------
Vish
Help others too


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 24, 2004 10:53 am 
Regular
Regular

Joined: Thu Aug 28, 2003 10:54 am
Posts: 67
Its definitely mapped i.e. <mapping resource="com/wdb/sites/WebSite.hbm.xml"/>

Hibernate's logging clearly show the mapping gets loaded OK. I think the problem is that i want to use the interface WebSite in the HQL but hibernate expects the concrete class WebSiteImpl ( when i do the substitution the query completes fine).

I suppose I need to use a joined-subclass with a discriminator column. I wish you could set the discriminator to null though as I only want to use one concrete persistent class.


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.