Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search.count() does not work with composite id's #91

Open
GoogleCodeExporter opened this issue Feb 9, 2016 · 4 comments
Open

Search.count() does not work with composite id's #91

GoogleCodeExporter opened this issue Feb 9, 2016 · 4 comments

Comments

@GoogleCodeExporter
Copy link

If using Entities with composite Id's, e.g. like

@Entity
@Table(name = "Products", catalog = "Utility")
public class Products implements java.io.Serializable {

    private ProductsId id;
    private String productGroupName;

..... }

and the corresponding Id class:

@Embeddable
public class ProductsId implements java.io.Serializable {

    private String  facility;
    private String  productGroup;
    private String  product;

.... }

and a DAO like this 

@Repository
public class ProductsHome extends GenericDAOImpl<Products, ProductsId> {
}


Now using search function "count()" will fail because the root alias "_it" will 
be expanded leading to invalid sql.

It will create invalid SQL like:

select count( (produ0_.Facility, produ0_.ProductGroup, produ0_.Product) as 
col_0_0_ from Utility.Products produ0_

this fails on mysql with error 1241.
/* SQL Error (1241): Operand should contain 1 column(s) */

What is the expected output? What do you see instead?
Expected is sql like:
select count((produ0_.Facility))
or 
select count (*) ....

What version of the product are you using? On what operating system?
1.0.0
Hibernate 3.6.5.Final

Original issue reported on code.google.com by flei...@gmail.com on 4 Jul 2011 at 11:44

@GoogleCodeExporter
Copy link
Author

I hope to look into this. There might be a different problem if we just use 
count(*); I seem to recall some issue.

In the mean time, the workaround might be to call searchUnique with a Search 
object that specifies a specific count column.

Original comment by dwolvert on 6 Jul 2011 at 11:44

@GoogleCodeExporter
Copy link
Author

Was this ever looked into?

Original comment by nels4...@gmail.com on 28 Jun 2012 at 4:26

@GoogleCodeExporter
Copy link
Author

Is this relevant anymore?

Original comment by pablit...@gmail.com on 14 Jun 2014 at 7:15

@GoogleCodeExporter
Copy link
Author

hi all, i  use 1.1.0 and also got this issue when call searchAndCount(),
Hibernate: 
    select
        count((signatoryc0_.ACC_ID,
        signatoryc0_.CARD_VER)) as col_0_0_ 
    from
        CHQ_ACC_SIG_CARD_TBL signatoryc0_ 
    where
        signatoryc0_.ACC_ID=?
2014-06-28 09:42:37,063 [JDBCExceptionReporter]: SQL Error: 1241, SQLState: 
21000

any suggestion.. btw, for some reason, i need to use hiberante3, so i use 
1.1.0, but not 1.2.0, thanks..

Original comment by weiguang...@gmail.com on 28 Jun 2014 at 2:02

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant