-->
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: Problem with mapped query and <properties> element
PostPosted: Wed Aug 10, 2005 2:39 am 
Beginner
Beginner

Joined: Wed Aug 10, 2005 12:09 am
Posts: 30
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.0.3

Mapping documents:
<properties name="ttblKey" unique="true">
<property name="ucVcmpId" type="java.lang.String" column="U##CMP_ID" length="2"/>
<property name="ttblId" type="java.math.BigDecimal" column="TTBL_ID" length="22"/>
</properties>
...
<query name="getNextTimetableNo"><![CDATA[
select max(t.ttableNo) from Ttbl as t
where t.ucVcmpId = 'TA'
and t.ucVempId = :pempId
]]>
</query>
...
Code between sessionFactory.openSession() and session.close():
session obtained from jndi lookup

Full stack trace of any exception that occurs:
10 Aug 2005 16:12:38,119 ERROR [impl.SessionFactoryImpl] - Error in named query: getNextTimetableNo
org.hibernate.QueryException: could not resolve property: ucVcmpId of: com.Ttbl [
select max(t.ttableNo) from com.Ttbl as t
where t.ucVcmpId = 'TA'
and t.ucVempId = :pempId
]
at org.hibernate.persister.entity.AbstractPropertyMapping.throwPropertyException(AbstractPropertyMapping.java:43)
at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:37)
at org.hibernate.persister.entity.BasicEntityPersister.toType(BasicEntityPersister.java:1094)
at org.hibernate.hql.ast.FromElementType.getPropertyType(FromElementType.java:230)
at org.hibernate.hql.ast.FromElement.getPropertyType(FromElement.java:342)
at org.hibernate.hql.ast.DotNode.getDataType(DotNode.java:474)
at org.hibernate.hql.ast.DotNode.prepareLhs(DotNode.java:207)
at org.hibernate.hql.ast.DotNode.resolve(DotNode.java:166)
at org.hibernate.hql.ast.FromReferenceNode.resolve(FromReferenceNode.java:88)
at org.hibernate.hql.ast.FromReferenceNode.resolve(FromReferenceNode.java:84)
at org.hibernate.hql.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:463)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:863)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:3713)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3190)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1405)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1330)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1330)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1330)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1330)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1330)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1330)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1330)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1330)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:599)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:404)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:201)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:151)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:84)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:425)
at org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:386)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:289)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1055)

Name and version of the database you are using:
Oracle 9i

The generated SQL (show_sql=true):
none

Debug level Hibernate log excerpt:
will post if necessary


The problems seems to be hibernate doesn't register the property inside the <properties> tag. If I add the property outside the <properties> tag then the query parses but I get a new exception that theres a duplicate column.

Does anyone know a proper solution how I can use this property in my named query? I'm not sure what I'm supposed to do in this case.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 7:45 am 
Beginner
Beginner

Joined: Wed Aug 10, 2005 12:09 am
Posts: 30
I "solved" this problem by adding update="false" insert="false" in the repeated property inside <properties> as advised by the helpful hibernate exception message - this allows the property column to be repeated - why is this necessary?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 8:37 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
shnplr wrote:
I "solved" this problem by adding update="false" insert="false" in the repeated property inside <properties> as advised by the helpful hibernate exception message - this allows the property column to be repeated - why is this necessary?


Because when Hibernate wants to persist the data, it needs to look for it in only 1 place. Having two fields mapped to the same data allows the possibility that you change one and not the other.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 7:53 pm 
Beginner
Beginner

Joined: Wed Aug 10, 2005 12:09 am
Posts: 30
Sorry, I didn't mean to rate the previous post unhelpful, it didn't solve my problem, however it WAS helpful and deserve credit - I understand now the reason but I actually dont want to repeat the column, hibernate is forcing me to repeat the column because the mapped query can't "see" the <property> nested in <properties> tag. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 11:23 pm 
Senior
Senior

Joined: Thu May 12, 2005 11:40 pm
Posts: 125
Location: Canada
You don't have to repeat the property, just prefix the <property> name with the <properties> name when referring to it.

Code:
ttblKey.ucVcmpId


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.