-->
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.  [ 4 posts ] 
Author Message
 Post subject: SELECT NEW: unable to locate POJO class
PostPosted: Tue Feb 10, 2009 12:08 pm 
Newbie

Joined: Tue Feb 10, 2009 11:37 am
Posts: 1
I am executing a query as follows. It results in a compiler error because the POJO class is not found.

Code:
Query q = entityManager.createQuery("SELECT NEW org.domain.b1.ui.NonMappedClass(b.prop1, b.prop2) ...


The compiler in eclipse finds an HQL Syntax Error: unable to locate class [org.domain.b1.ui.NonMappedClass]. The class exists and may be instantiated normally outside of a query. It's a POJO class that's not in the same package as the Hibernate entities that were created from the database tables. From within the HQL Editor, this query works fine. It just won't compile in my code! I think I need to somehow notify Hibernate of this POJO class so that it is visible during compile. Any ideas how to do that? Is it a certain @ Annotation I need, or do I need to create a hibernate config xml file? Or maybe there is a completely different solution. Regardless, thank you for helping.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 10, 2009 2:53 pm 
Regular
Regular

Joined: Fri Jan 30, 2009 10:10 am
Posts: 74
Location: London
I don't know whether you should expect Hibernate to be able to manage entities that it isn't responsible for persisting.

--
Stephen Souness


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2009 3:27 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
Quote:
I don't know whether you should expect Hibernate to be able to manage entities that it isn't responsible for persisting.

SELECT NEW does exactly that. When using SELECT NEW you dont need to specify a mapped entity type. You can specify any POJO class, its only that you should have a matching constructor in ur POJO class.
See the part "Cases where joined queries aren't enough" of
http://www.javalobby.org/articles/hibernate-query-101/
and
http://www.theserverside.com/discussion ... d_id=28872

Well coming to the issue in the post, the query should be working even if the POJO class is outside of hibernate entity class. Can you post the relevant code, mapping and the stack trace you are getting.

_________________
Regards,
Litty Preeth


Top
 Profile  
 
 Post subject: Re: SELECT NEW: unable to locate POJO class
PostPosted: Thu Feb 18, 2010 12:31 pm 
Newbie

Joined: Thu Feb 18, 2010 12:26 pm
Posts: 1
You need to use the import keyword. Just create a simple hbm file like so:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="myassembly" namespace="mynamespace">
<import class="MyClassThatsJustAPOJO" />
</hibernate-mapping>


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