-->
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.  [ 5 posts ] 
Author Message
 Post subject: Named Query Error
PostPosted: Fri Feb 11, 2005 8:41 am 
Newbie

Joined: Fri Feb 11, 2005 7:20 am
Posts: 18
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

[b]Hibernate version:[/b]

Hibernate 3.0 beta

[b]Mapping documents:[/b]

Links.hbm.xml
-----------------

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1

http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->

<class
name="test.Links"
table="LINKS">
<meta attribute="class-description" inherit="false">
@hibernate.class
table="LINKS"
</meta>

<composite-id name="comp_id" class="test.LinksPK">
<meta attribute="field-description" inherit="false">
@hibernate.id
generator-class="assigned"
</meta>
<key-property
name="parentId"
column="PARENT_ID"
type="java.lang.Long"
length="22"
>
<meta attribute="field-description">
@hibernate.property
column="PARENT_ID"
length="22"
</meta>
</key-property>
<key-property
name="childId"
column="CHILD_ID"
type="java.lang.Long"
length="22"
>
<meta attribute="field-description">
@hibernate.property
column="CHILD_ID"
length="22"
</meta>
</key-property>
<key-property
name="linkId"
column="LINK_ID"
type="java.lang.Long"
length="22"
>
<meta attribute="field-description">
@hibernate.property
column="LINK_ID"
length="22"
</meta>
</key-property>
</composite-id>

<property
name="value"
type="java.lang.Float"
column="VALUE"
length="16"
>
<meta attribute="field-description">
@hibernate.property
column="VALUE"
length="16"
</meta>
</property>
</class>

<sql-query name="AllLinks">
<return alias="l" class="test.Links" lock-mode="upgrade"/>
SELECT VALUE AS {l.value} FROM Links WHERE {l}.value =?

</sql-query>
</hibernate-mapping>

[b]Code between sessionFactory.openSession() and session.close():[/b]

Session s = factory.openSession();
try
{
List links = s.getNamedQuery("AllLinks").setDouble(0, 99.99).list();
Iterator iter = links.iterator();

while ( iter.hasNext() )
{
Links link = (Links) iter.next();
System.out.println("\nLink Value: " + link.getValue());
}
}

[b]Full stack trace of any exception that occurs:[/b]

org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.ErrorCodeConverter.convert
(ErrorCodeConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert
(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1364)
at org.hibernate.loader.Loader.list(Loader.java:1344)
at org.hibernate.loader.CustomLoader.list(CustomLoader.java:101)
at org.hibernate.impl.SessionImpl.listCustomQuery
(SessionImpl.java:1705)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:146)
at test.TestHSQL.listAllLinks(TestHSQL.java:120)
at test.TestHSQL.main(TestHSQL.java:68)
Caused by: java.sql.SQLException: ORA-00904: "L"."VALUE": invalid identifier

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe
(TTC7Protocol.java:830)
at oracle.jdbc.driver.OracleStatement.doExecuteQuery
(OracleStatement.java:2391)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout
(OracleStatement.java:2672)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate
(OraclePreparedStatement.java:589)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery
(OraclePreparedStatement.java:527)
at org.hibernate.jdbc.AbstractBatcher.getResultSet
(AbstractBatcher.java:108)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1109)
at org.hibernate.loader.Loader.doQuery(Loader.java:349)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections
(Loader.java:195)
at org.hibernate.loader.Loader.doList(Loader.java:1361)
... 6 more


[b]Name and version of the database you are using:[/b]

Oracle 9
[b]The generated SQL (show_sql=true):[/b]

SELECT VALUE AS VALUE1_0_ FROM Links WHERE l.value =?

[b]Debug level Hibernate log excerpt:[/b]
7:35:30,130 INFO Environment:451 - Hibernate 3.0 beta 3
17:35:30,161 INFO Environment:469 - loaded properties from resource hibernate.properties: {hibernate.order_updates=true, hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver, hibernate.cglib.use_reflection_optimizer=true, hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider, hibernate.max_fetch_depth=1, hibernate.dialect=org.hibernate.dialect.Oracle9Dialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.connection.username=hibernate, hibernate.cache.region_prefix=hibernate.test, hibernate.connection.url=jdbc:oracle:thin:@192.168.210.109:1521:EIPTEST1, hibernate.show_sql=true, hibernate.connection.password=hibernate321, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=1}
17:35:30,161 INFO Environment:496 - using java.io streams to persist binary types
17:35:30,161 INFO Environment:497 - using CGLIB reflection optimizer
17:35:30,161 INFO Environment:527 - using JDK 1.4 java.sql.Timestamp handling
17:35:30,161 INFO Configuration:456 - Mapping resource: test/Dept.hbm.xml
17:35:30,630 INFO HbmBinder:437 - Mapping class: test.Dept -> Dept
17:35:30,661 INFO Configuration:456 - Mapping resource: test/Links.hbm.xml
17:35:30,708 INFO HbmBinder:437 - Mapping class: test.Links -> LINKS
17:35:30,724 INFO Configuration:821 - processing extends queue
17:35:30,724 INFO Configuration:825 - processing collection mappings
17:35:30,724 INFO Configuration:834 - processing association property references
17:35:30,724 INFO Configuration:861 - processing foreign key constraints
17:35:30,989 INFO Dialect:86 - Using dialect: org.hibernate.dialect.Oracle9Dialect
17:35:31,005 INFO SettingsFactory:86 - Maximum outer join fetch depth: 1
17:35:31,005 INFO SettingsFactory:89 - Default batch fetch size: 1
17:35:31,005 INFO SettingsFactory:93 - Generate SQL with comments: disabled
17:35:31,005 INFO SettingsFactory:97 - Order SQL updates by primary key: enabled
17:35:31,005 INFO SettingsFactory:267 - Query translator: org.hibernate.hql.classic.ClassicQueryTranslatorFactory
17:35:31,021 INFO SettingsFactory:105 - Query language substitutions: {no='N', true=1, yes='Y', false=0}
17:35:31,021 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
17:35:31,021 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 1
17:35:31,021 INFO DriverManagerConnectionProvider:45 - autocommit mode: false
17:35:31,068 INFO DriverManagerConnectionProvider:80 - using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@192.168.210.109:1521:EIPTEST1
17:35:31,068 INFO DriverManagerConnectionProvider:86 - connection properties: {user=hibernate, password=****}
17:35:31,599 INFO SettingsFactory:146 - JDBC batch size: 15
17:35:31,599 INFO SettingsFactory:149 - JDBC batch updates for versioned data: enabled
17:35:31,599 INFO SettingsFactory:154 - Scrollable result sets: enabled
17:35:31,599 INFO SettingsFactory:162 - JDBC3 getGeneratedKeys(): disabled
17:35:31,599 INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
17:35:31,599 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
17:35:31,599 INFO SettingsFactory:174 - Automatic flush during beforeCompletion(): disabled
17:35:31,599 INFO SettingsFactory:177 - Automatic session close at end of transaction: disabled
17:35:31,599 INFO SettingsFactory:254 - Cache provider: org.hibernate.cache.HashtableCacheProvider
17:35:31,614 INFO SettingsFactory:185 - Second-level cache: enabled
17:35:31,614 INFO SettingsFactory:190 - Optimize cache for minimal puts: disabled
17:35:31,614 INFO SettingsFactory:194 - Cache region prefix: hibernate.test
17:35:31,614 INFO SettingsFactory:197 - Structured second-level cache entries: enabled
17:35:31,614 INFO SettingsFactory:201 - Query cache: disabled
17:35:31,614 INFO SettingsFactory:208 - Echoing all SQL to stdout
17:35:31,614 INFO SettingsFactory:212 - Statistics: disabled
17:35:31,614 INFO SettingsFactory:216 - Deleted entity synthetic identifier rollback: disabled
17:35:31,708 INFO SessionFactoryImpl:142 - building session factory
17:35:31,974 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
17:35:31,974 INFO SessionFactoryImpl:368 - Checking 0 named queries

_________________
Thanks in advance,
Lakshmi


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 11, 2005 10:17 am 
Regular
Regular

Joined: Fri Sep 17, 2004 10:51 am
Posts: 61
Location: Rimini, Italy
You didn't specified the alias for the table.
The query should be:
Code:
SELECT {l}.VALUE AS {l.value} FROM Links {l} WHERE {l}.value =?

_________________
--
Marco


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 11, 2005 10:34 am 
Newbie

Joined: Fri Feb 11, 2005 7:20 am
Posts: 18
When i try to execute the query it works.

For eg.
Query query = session.createSQLQuery("select {d}.* from dept as {d}");
But i need values of the result.so when i try "query.srcoll()" it throws
"Exception in method .....org.hibernate.exception.SQLGrammarException: could not execute query using scroll"
can't i take the results into a "Dept" object? dept is my table name and "Dept" is the corresponding hibernate class name.

i can do
Object obj = (Object) session.createSQLQuery("select {d}.* from dept as {d}");

but
Dept obj = (Dept) session.createSQLQuery("select {d}.* from dept as {d}");
is not working.

_________________
Thanks in advance,
Lakshmi


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 11, 2005 10:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
don't use scroll, use list


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 12, 2005 6:48 am 
Newbie

Joined: Fri Feb 11, 2005 7:20 am
Posts: 18
even list is giving me error.

_________________
Thanks in advance,
Lakshmi


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