-->
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.  [ 12 posts ] 
Author Message
 Post subject: MappingException: Named query not known :
PostPosted: Mon Aug 13, 2007 8:00 am 
Newbie

Joined: Mon Aug 13, 2007 6:38 am
Posts: 16
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3

<hibernate-mapping package="com.cl.pojo">
<class name="Address" table="ADDRESS">
<id name="id" type="long" column="ID" >
<generator class="increment"/>
</id>

<property name="std_id">
<column name="STD_ID" />
</property>
<property name="city">
<column name="CITY"/>
</property>
<property name="phone">
<column name="PHONE"/>
</property>


</class>
<query name="GetAllAddress">
<![CDATA[from com.cl.pojo.Address]]>
</query>

</hibernate-mapping>:


Code between sessionFactory.openSession() and session.close():

org.hibernate.MappingException: Named query not known: GetAllAddress
at org.hibernate.impl.AbstractSessionImpl.getNamedQuery(AbstractSessionImpl.java:70)
at org.hibernate.impl.SessionImpl.getNamedQuery(SessionImpl.java:1224)
at _jsp._clzone._reports._erp._namedquery__jsp._jspService(/clzone/reports/erp/NamedQuery.jsp:32)
at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
at com.caucho.jsp.Page.pageservice(Page.java:571)
at com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:155)
at com.caucho.server.cache.CacheFilterChain.doFilter(CacheFilterChain.java:177)
at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:177)
at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:221)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:263)
at com.caucho.server.port.TcpConnection.run(TcpConnection.java:331)
at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:464)
at com.caucho.util.ThreadPool.run(ThreadPool.java:408)
at java.lang.Thread.run(Thread.java:534)

:


Name and version of the database you are using:Oracle 10g

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


As u have seen the query named "GetAllAddress" is not been recognised.I tried use it within the class tag and outside it ...but could't able to run it.

So plz help me ... becoz for now i got stuck...
I used Query as ---
List addr = session2.getNamedQuery("GetAllAddress").list();
for(Iterator itr=addr.iterator();itr.hasNext();)
{
Address a = (Address)itr.next();
long ID = a.getId();
int FirstName = a.getStd_id();
String Phone = a.getPhone();
String City = a.getCity();
}

Thanx in advanced.....


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 13, 2007 4:01 pm 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
The full name of named queries includes the package and class name. Try this:
List addr = session2.getNamedQuery("com.cl.pojo.Address.GetAllAddress").list();


Top
 Profile  
 
 Post subject: Still the same error is coming !!!
PostPosted: Tue Aug 14, 2007 12:44 am 
Newbie

Joined: Mon Aug 13, 2007 6:38 am
Posts: 16
Thanx for the reply, but I got the same exception
org.hibernate.MappingException: Named query not known: com.cl.pojo.Address.GetAllAddress
at org.hibernate.impl.AbstractSessionImpl.getNamedQuery(AbstractSessionImpl.java:70)
at org.hibernate.impl.SessionImpl.getNamedQuery(SessionImpl.java:1224)
at _jsp._clzone._reports._erp._namedquery__jsp._jspService(/clzone/reports/erp/NamedQuery.jsp:32)
at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
at com.caucho.jsp.Page.pageservice(Page.java:571)
at com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:155)
at com.caucho.server.cache.CacheFilterChain.doFilter(CacheFilterChain.java:211)
at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:177)
at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:221)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:263)
at com.caucho.server.port.TcpConnection.run(TcpConnection.java:331)
at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:464)
at com.caucho.util.ThreadPool.run(ThreadPool.java:408)
at java.lang.Thread.run(Thread.java:534)


So plz. provide some more suggestions , so that I would be able to run it.
Regards,
Abhishek


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 14, 2007 12:53 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi abhibh,

check that this hbm is included in session factory or not

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 14, 2007 1:19 am 
Newbie

Joined: Mon Aug 13, 2007 6:38 am
Posts: 16
Hello,
Yes, I have incuded "Address.hbm.xml" in the "hibernate.cfg.xml" file:-

<mapping resource = "com/cl/pojo/Address.hbm.xml"/>

During the start of the server, it shows the mapping b/w the class and the corresponding table.

But as far as the query is concerned its named is not recognized.
So what to do...

Regards,
Abhishek


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 14, 2007 2:27 am 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
Quote:
During the start of the server, it shows the mapping b/w the class and the corresponding table

Can you post this part of the output please.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 14, 2007 2:59 am 
Newbie

Joined: Mon Aug 13, 2007 6:38 am
Posts: 16
Hello Mike,
The output shown by the server when it loadsthe session factory is:

[12:09:39.125] Compiling _jsp/_clzone/_reports/_erp/_namedquery__jsp.java
[12:09:41.937] Hibernate 3.1.3
[12:09:42.015] hibernate.properties not found
[12:09:42.031] using CGLIB reflection optimizer
[12:09:42.031] using JDK 1.4 java.sql.Timestamp handling
Unable to create the InitialContext
Session factory not found in JNDI. Creating new

[12:09:43.203] configuring from resource: /hibernate.cfg.xml
[12:09:43.203] Configuration resource: /hibernate.cfg.xml
[12:09:44.140] Reading mappings from resource: com/cl/pojo/contact.hbm.xml
[12:09:44.984] Mapping class: com.cl.pojo.Contact -> CONTACT
[12:09:45.468] Reading mappings from resource: com/cl/pojo/Address.hbm.xml
[12:09:45.515] Mapping class: com.cl.pojo.Address -> ADDRESS
[12:09:45.531] Configured SessionFactory: null

[12:09:46.656] Configuring Proxool Provider using JAXPConfigurator: proxool.xml
[12:09:46.875] Proxool 0.9.0RC3 (10-Jan-2007 01:38)
[12:09:47.562] Configuring Proxool Provider to use pool alias: proxool.xml-test
[12:09:47.562] autocommit mode: false
[12:09:50.937] RDBMS: Oracle, version: Oracle Database 10g Enterprise Edition Re
lease 10.2.0.1.0 - Production
[12:09:50.937] With the Partitioning, OLAP and Data Mining options
[12:09:50.937] JDBC driver: Oracle JDBC driver, version: 9.2.0.1.0
[12:09:51.343] Using dialect: org.hibernate.dialect.OracleDialect
[12:09:51.468] Using default transaction strategy (direct JDBC transactions)
[12:09:51.515] No TransactionManagerLookup configured (in JTA environment, use o
f read-write or transactional second-level cache is not recommended)
[12:09:51.515] Automatic flush during beforeCompletion(): disabled
[12:09:51.515] Automatic session close at end of transaction: disabled
[12:09:51.515] JDBC batch size: 15
[12:09:51.515] JDBC batch updates for versioned data: disabled
[12:09:51.531] Scrollable result sets: enabled
[12:09:51.531] JDBC3 getGeneratedKeys(): disabled
[12:09:51.531] Connection release mode: auto
[12:09:51.546] Default batch fetch size: 1
[12:09:51.546] Generate SQL with comments: disabled
[12:09:51.546] Order SQL updates by primary key: disabled
[12:09:51.546] Query translator: org.hibernate.hql.classic.ClassicQueryTranslato
rFactory
[12:09:51.609] Query language substitutions: {}
[12:09:51.609] Second-level cache: enabled
[12:09:51.609] Query cache: disabled
[12:09:51.609] Cache provider: org.hibernate.cache.EhCacheProvider
[12:09:51.671] Optimize cache for minimal puts: disabled
[12:09:51.687] Structured second-level cache entries: disabled
[12:09:51.828] Statistics: disabled
[12:09:51.828] Deleted entity synthetic identifier rollback: disabled
[12:09:51.828] Default entity-mode: pojo
[12:09:52.265] building session factory
[12:09:52.375] No configuration found. Configuring ehcache from ehcache-failsafe
.xml found in the classpath: jar:file:/d:/webapps/clsite/cl/WEB-INF/lib/ehcache-
1.1.jar!/ehcache-failsafe.xml
[12:09:57.250] Not binding factory to JNDI, no JNDI name configured
[12:09:57.312] Running hbm2ddl schema update
[12:09:57.312] fetching database metadata
[12:09:57.500] updating schema
[12:09:57.593] table found: ERP.ADDRESS
[12:09:57.593] columns: [phone, city, std_id, id]
[12:09:57.593] foreign keys: []
[12:09:57.593] indexes: []
[12:09:57.687] table found: ERP.CONTACT
[12:09:57.687] columns: [lastname, firstname, email, id]
[12:09:57.687] foreign keys: []
[12:09:57.687] indexes: [sys_c0012505]
[12:09:57.687] schema update complete
[12:12:46.484] Compiling _jsp/_clzone/_reports/_erp/_namedquery__jsp.java
[12:13:58.375] Compiling

I have tried everything, but not able to run it.
In the mapping file I have written
<query name="allAddress">
<![CDATA[from com.cl.pojo.Address]]>
</query>
also tried
<![CDATA[ From Address ]]>
And in the jsp I have written:
List addr = session2.getNamedQuery("allAddress").list(); and
List addr = session2.getNamedQuery("com.cl.pojo.Address.allAddress").list();


But nothing seemed to work properly
Waiting for ur useful suggestions...

Regards
Abhishek


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 14, 2007 3:13 am 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
Turn on hibernate debug and restart server. You should see something like this:
07:26:22,265 DEBUG HbmBinder:18 - Named query: AllUk ->
from Soldier s join fetch s.addresses a where a.country='uk'


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 14, 2007 3:34 am 
Newbie

Joined: Mon Aug 13, 2007 6:38 am
Posts: 16
Hello

By enabling the debugging option ,u mean to say that ,setting
<property name="hibernate.show_sql">true</property>
<property name="hibernate.use_sql_comments">true</property>


But even after that the query name is not mentioned on the console.

If i use

query = session2.createQuery("from Address");
List addr = query.list();
directly using it...then output on server's console is:
Hibernate: /* from Address */ select address0_.ID as ID1_, address0_.STD_ID as S
TD2_1_, address0_.CITY as CITY1_, address0_.PHONE as PHONE1_ from ADDRESS addres
s0_
and this is working properly...

But what is the problem with using the named query...God Knows

Regards,
Abhishek


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 14, 2007 3:43 am 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
No, I mean enabling debug logging. In log4j.properties:
log4j.logger.org.hibernate=debug


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 14, 2007 4:23 am 
Newbie

Joined: Mon Aug 13, 2007 6:38 am
Posts: 16
Hello,
As I don't know much about log4j , so in the log4j property file I have put
"log4j.logger.org.hibernate=debug"
as this property "log4j.logger.org.hibernate" was not earlier present in property file.

But nothing seemed to work.
If i want to perform logging on the server's console then what should I do.

Thanx in advance


Top
 Profile  
 
 Post subject: Is hibernate3.jar is incompatible with Resin server ???
PostPosted: Thu Aug 16, 2007 12:41 am 
Newbie

Joined: Mon Aug 13, 2007 6:38 am
Posts: 16
Hello,

The problem which I have mensioned in this post is solved somehow...
The thing was that, right now I am using jdk1.4 and Resin as a server and when I run this jsp then it used to give the same problem i.e. unable to find the query name.
But when I run the same jsp with jdk1,5 and Tomcat as a server then it runs well.
So, is hibernate3.jar is incompatible with Resin???Because I have to work with Resin.
So what would be the solution to this...

Thanx in advance.
Regards,
Abhishek[/b]


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