-->
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.  [ 9 posts ] 
Author Message
 Post subject: HQL and sets of CompositeUserType
PostPosted: Fri Jun 17, 2005 9:37 pm 
Beginner
Beginner

Joined: Wed Dec 31, 2003 1:40 pm
Posts: 25
I have a problem with HQL querying a structure like this:

<class name="eg.Role" ...>
...
<property name="simpleId" type="II">
<column name="simpleId_root" sql-type="VARCHAR" length="255"/>
<column name="simpletId_extension" sql-type="VARCHAR" length="255"/>
</property>

<set name="id" table="Role_id" lazy="true" access="eg.WrappingSetAccessor" sort="unsorted" inverse="false" batch-size="1" outer-join="auto" optimistic-lock="true">
<key column="Role_INTERNAL_ID" on-delete="noaction"/>
<element type="II" not-null="false" unique="false">
<column name="root" sql-type="VARCHAR" length="255"/>
<column name="extension" sql-type="VARCHAR" length="255"/>
</element>
</set>
...
</class>

the following query works

from eg.Role as role where role.simpleId.extension='test'

so I know that the mapping of this composite user type "II" works fine.

This query also works:

from eg.Role as role inner join role.id as roleid where roleid.extension='test'

this now fails with Invalid path: 'roleid.extension'

What am I missing? Shouldn't the properties of the set element be dereferencable just like the properties of the simple component type?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 22, 2005 7:12 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
version?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 12:04 pm 
Beginner
Beginner

Joined: Wed Dec 31, 2003 1:40 pm
Posts: 25
emmanuel wrote:
version?


It is 3.1 rc1 now, and any version before. Here is what happens now:

[java] Exception in thread "main" java.lang.NullPointerException
[java] at org.hibernate.hql.ast.HqlSqlWalker.createFromJoinElement(HqlSqlWalker.java:312)
[java] at org.hibernate.hql.antlr.HqlSqlBaseWalker.joinElement(HqlSqlBaseWalker.java:3252)
[java] at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3044)
[java] at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2922)
[java] at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:690)
[java] at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:546)
[java] at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:283)
[java] at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:231)
[java] at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:214)
[java] at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:154)
[java] at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:101)
[java] at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:473)
[java] at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1032)
[java] at org.hibernate.impl.SessionImpl.list(SessionImpl.java:982)
[java] at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
[java] at Test.getSomeRole(Test.java:51)
[java] at Test.run(Test.java:35)
[java] at Test.main(Test.java:18)
[java] Java Result: 1


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 1:41 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
When used to dereference from an entity alias, 'id' always refers to the entity's id property. Thus, you cannot have fields named 'id' on your entities if you expect to be able to use them in HQL.

Quote:
this now fails with ...

At what point did this ever work for you?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 5:42 pm 
Beginner
Beginner

Joined: Wed Dec 31, 2003 1:40 pm
Posts: 25
steve wrote:
When used to dereference from an entity alias, 'id' always refers to the entity's id property. Thus, you cannot have fields named 'id' on your entities if you expect to be able to use them in HQL.


Ahhhh! That explains it.

Quote:
At what point did this ever work for you?


It never worked. I ended up not using HQL and used SQL instead because I thought HQL would not work.

It's sad though, because I don't have control over those identifiers like "id" they are set by a standard data model that I am implementing. Is there any way to make the hibernate id be called different? I call them "internalId" in my model. I may have to alias my id name...


Top
 Profile  
 
 Post subject: Annoyance with HQL special id property
PostPosted: Mon Dec 05, 2005 1:43 pm 
Beginner
Beginner

Joined: Wed Dec 31, 2003 1:40 pm
Posts: 25
I'd like to follow up on this.

The special property 'id' in HQL is a great annoyance to me, a showstopper, becasue I can't just decide not to use the name "id" for a normal property. My API/Object Model is from a standard and needs to use the standard names.

I have filed a bug report at http://opensource2.atlassian.com/projects/hibernate/browse/HHH-1127
with a patch that "fixes" the problem for me. But that was simply closed without further comment, marked as "duplicate" without a link to the bug or discussion that it supposedly duplicates.

I think this is bad design of HQL and should somehow be repealed. It's an entirely unnecessary "feature" because all id properties have a normal name defined in the mapping file. If they wanted a "feature" they shouldn't just use up a normal looking property name, instead they should have used some special tag, such as x.@id or x.hibernateId or something less likely to conflict.


Top
 Profile  
 
 Post subject: Re: Annoyance with HQL special id property
PostPosted: Tue Dec 06, 2005 5:51 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
gschadow wrote:
I think this is bad design of HQL and should somehow be repealed. It's an entirely unnecessary "feature" because all id properties have a normal name defined in the mapping file. If they wanted a "feature" they shouldn't just use up a normal looking property name, instead they should have used some special tag, such as x.@id or x.hibernateId or something less likely to conflict.


This is not a bad design of HQL and is mandatory when there is no id property for an entity.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: Annoyance with HQL special id property
PostPosted: Thu Dec 08, 2005 10:56 pm 
Beginner
Beginner

Joined: Wed Dec 31, 2003 1:40 pm
Posts: 25
emmanuel wrote:
gschadow wrote:
I think this is bad design of HQL and should somehow be repealed. It's an entirely unnecessary "feature" because all id properties have a normal name defined in the mapping file. If they wanted a "feature" they shouldn't just use up a normal looking property name, instead they should have used some special tag, such as x.@id or x.hibernateId or something less likely to conflict.


This is not a bad design of HQL and is mandatory when there is no id property for an entity.


Then what is it? It's making perhaps the most common property name into a reserved word without need. A special form @id or hibernateId would have been no problem or at least some mechanism to "escape" the reserved word in HQL to say "I really mean my property that I called id". Ah well, it's easy enough for me to keep as my hack. :P


Top
 Profile  
 
 Post subject: Re: Annoyance with HQL special id property
PostPosted: Sat Dec 10, 2005 1:39 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
gschadow wrote:
Then what is it? It's making perhaps the most common property name into a reserved word without need.

You're using the most comming property name for property id as a non id property ;-)

_________________
Emmanuel


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