-->
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.  [ 1 post ] 
Author Message
 Post subject: discount counts using composite keys
PostPosted: Sat Sep 01, 2007 4:57 pm 
Newbie

Joined: Sat Sep 01, 2007 4:39 pm
Posts: 1
[code]
@Entity
class Sample {
@EmbeddedId
Key id;
}
[/code]


[code]
@Embeddable
class Key {
someProperty;
otherProperty;
}
[/code]

Everything works fine when I do:

[code]
select count(*) from Sample s
[/code]

But problems arise with a query like:

[code]
select count(s) from Sample s
[/code]

In this latter example, since Sample has a composite key, the generated sql looks like:

[code]
select count(sample_table.some_property, sample_table.other_property)
[/code]

On postgres, you'd receive an error like:

[quote]
ERROR: function count(<some_type>, <other_type>) does not exist
SQL state: 42883
Hint: No function matches the given name and argument types. You may need to add explicit type casts.
Character: 11
[/quote]

Obviously, for this particular example, I can use the count(*) syntax and be just fine, but I can't do that in the original context this problem comes from. In that other context, this count is part of a larger select/groupby statement which would make the count(*) syntax ambiguous.

If I use count(s.id.someProperty) or count(s.id.otherProperty), it generates sql that is valid and runs, but it doesn't solve the problem because neither of those single properties uniquely identifies the row.

So my question: is there a way to count entities with composite primary keys in a database-agnostic way in HQL?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.