mandragorasster / hibernate-generic-dao

Automatically exported from code.google.com/p/hibernate-generic-dao
0 stars 0 forks source link

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

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
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 commented 8 years ago
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 commented 8 years ago
Was this ever looked into?

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

GoogleCodeExporter commented 8 years ago
Is this relevant anymore?

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

GoogleCodeExporter commented 8 years ago
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