-->
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: annotations, query not mapped, although proper
PostPosted: Sun Sep 06, 2009 2:38 am 
Newbie

Joined: Thu Aug 27, 2009 3:56 pm
Posts: 10
ClientApp, Java:
Code:
@Entity
@Table(name = "ClientApp", uniqueConstraints = @UniqueConstraint(columnNames = "appID"))


Query methods, java (note that APP_ID actually represents appId:
Code:
public List<ClientApp> findByProperty(String propertyName, Object value) {
      log.debug("finding ClientApp instance with property: " + propertyName
            + ", value: " + value);
      try {
         String queryString = "from ClientApp as model where model."
               + propertyName + "= ?";
         Query queryObject = getSession().createQuery(queryString);
         queryObject.setParameter(0, value);
         return queryObject.list();
      } catch (RuntimeException re) {
         log.error("find by property name failed", re);
         throw re;
      }
   }

   public List<ClientApp> findByAppId(Object appId) {
      return findByProperty(APP_ID, appId);
   }


Relevant parts of the trace:
Code:
Sep 06 02:24:01 (ErrorCounter.java:68) DEBUG org.hibernate.hql.ast.ErrorCounter  - throwQueryException() : no errors
Sep 06 02:24:01 (HqlSqlBaseWalker.java:111) DEBUG org.hibernate.hql.antlr.HqlSqlBaseWalker  - select << begin [level=1, statement=select]
Sep 06 02:24:01 (ClientAppDAO.java:108) ERROR com.medialets.orm.hib.ClientAppDAO  - find by property name failed
org.hibernate.hql.ast.QuerySyntaxException: ClientApp is not mapped [from ClientApp as model where model.appId= ?]
   at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:158)


every possible thread I've found on this have all been due to mismatch between table and class names, or using a table name instead of a class name, or mispelling, or something that would cause hibernate to not grab the mapping. But my mapping is definitely correct: table is ClientApp and Class is ClientApp, and the query string uses ClientApp. The other solution was making sure you're using javax.persistence.Entity and not the hibernate...Entity package, which I'm also doing.

What else could cause this? It's brain dead simple query...

Thanks, Bill


Top
 Profile  
 
 Post subject: Re: annotations, query not mapped, although proper
PostPosted: Sun Sep 06, 2009 10:49 am 
Newbie

Joined: Thu Aug 27, 2009 3:56 pm
Posts: 10
If I add the full package name to the class in the query string, I get a new exception:

Code:
Sep 06 10:41:03 (QueryPlanCache.java:76) DEBUG org.hibernate.engine.query.QueryPlanCache  - located HQL query plan in cache (from com.mycompany.orm.hib.ClientApp as model where model.appId= ?)
Sep 06 10:41:03 (ClientAppDAO.java:108) ERROR com.mycompany.orm.hib.ClientAppDAO  - find by property name failed
java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based!


I should mention that this is just a simple jar app; not a web app, and I'm using a generated DAO class from simply reverse engineering the db in eclipse using one of the hibernate plug ins. It appeared to have worked ok, certainly the code generated named and mapped everything ok and it seems consistent with other examples I've seen. Just wanted to mention it in case that could be part of the problem.


Top
 Profile  
 
 Post subject: Re: annotations, query not mapped, although proper
PostPosted: Sun Sep 06, 2009 11:31 am 
Newbie

Joined: Thu Aug 27, 2009 3:56 pm
Posts: 10
and I added the catalog mapping to point to the correct db (using mysql 5.1) which had been missing from the previous table annotation. still no love from hibernate. This is ridiculous


Top
 Profile  
 
 Post subject: Re: annotations, query not mapped, although proper
PostPosted: Tue Sep 08, 2009 1:40 am 
Newbie

Joined: Thu Aug 27, 2009 3:56 pm
Posts: 10
turns out that it wasn't finding hibernate.properties or hibernate.cfg.xml on the classpath, which was due to the default maven build not copying anything but compiled .class files to the build directory. Typical stupid java junk; if you're not fighting with one technology and spending all your time "configuring" crap, you're doing it with another. So, instead of fighting with maven, I decided to load the file from someplace else, but apparently, hibernate doesn't like that either. Still not finding the properties, still not working.


Top
 Profile  
 
 Post subject: Re: annotations, query not mapped, although proper
PostPosted: Tue Sep 08, 2009 1:46 am 
Newbie

Joined: Thu Aug 27, 2009 3:56 pm
Posts: 10
and this is after making sure that there is a hibernate.cfg.xml file on the built classpath. how lame


Top
 Profile  
 
 Post subject: Re: annotations, query not mapped, although proper
PostPosted: Mon Sep 14, 2009 6:48 am 
Newbie

Joined: Thu Aug 27, 2009 3:56 pm
Posts: 10
as a follow up in case somebody else gets jammed up on this, there's a misleading section in the configuration section of the conceptual docs that claims you can set a different file when you do mySessionFactory = cfg.configure("my.hibernate.cfg.xml").buildSessionFactory()

It would seem that this would intelligently take a path to the file, but it doesn't. It does something pretty unhelpful by allowing you to specify a different "name" of the file that it will still expect to find on the default classpath. Additionally, there doesn't appear to be any way to get hibernate to do something smart like load the hibernate.cfg.xml file from someplace else and actually have it configure properly by parsing the xml file that you're forced to configure. No, it just ignores those and instead you have to configure the configuration object with idiotic calls on the cfg file and basically rebuild what it should otherwise be able to configure from the xml file you created in the first place.


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.