[Hibernate-JIRA] Created: (HHH-4603) Copy Predicate from a CriteriaQuery to another will cause QuerySyntaxException
by zhouyanming (JIRA)
Copy Predicate from a CriteriaQuery to another will cause QuerySyntaxException
------------------------------------------------------------------------------
Key: HHH-4603
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4603
Project: Hibernate Core
Issue Type: Bug
Components: entity-manager
Affects Versions: 3.5.0-Beta-2
Reporter: zhouyanming
I build a CriteriaQuery and I want count it before fetch data for pagination,so I need create a new CriteriaQuery for counting.
public long countByCriteria(CriteriaQuery cq) {
CriteriaBuilder cb = getCriteriaBuilder();
CriteriaQuery count = cb.createQuery(Long.class);
Root<T> root = count.from(cq.getResultType());
EntityType<T> entityType = metamodel.entity(cq.getResultType());
Expression idExpression = root.get(entityType.getSingularAttribute("id"));
count.select(cb.count(idExpression));
count.where(cq.getRestriction()); //here will cause exception
TypedQuery<Long> tq = em.createQuery(count);
return tq.getSingleResult();
}
@Test
public void testCountByCriteria() {
CriteriaBuilder cb = getCriteriaBuilder();
CriteriaQuery<User> cq = cb.criteriaQuery(User.class);
Root<User> root = cq.from(User.class);
EntityType<User> entityType = getMetamodel().entity(User.class);
Expression expression = root.get(entityType.getSingularAttribute("username"));
Predicate condition = cb.equal(expression, "admin");
cq.where(condition);
assertTrue(baseManager.countByCriteria(cq) > 0);
}
Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: Invalid path: 'generatedAlias1.username' [select count(generatedAlias0.id) from model.User as generatedAlias0 where generatedAlias1.username=:param0]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:855)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:138)
at org.hibernate.ejb.criteria.CriteriaQueryCompiler.compile(CriteriaQueryCompiler.java:104)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:148)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.orm.jpa.JpaTemplate$CloseSuppressingInvocationHandler.invoke(JpaTemplate.java:404)
... 38 more
Caused by: org.hibernate.hql.ast.QuerySyntaxException: Invalid path: 'generatedAlias1.username' [select count(generatedAlias0.id) from model.User as generatedAlias0 where generatedAlias1.username=:param0]
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:261)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:98)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1761)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:123)
... 48 more
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
16 years, 4 months
[Hibernate-JIRA] Created: (HHH-4589) HqlSqlWalker.createFromJoinElement throws java.lang.NullPointerException when join Embedded classes
by Rodrigo Carvalho Rezende (JIRA)
HqlSqlWalker.createFromJoinElement throws java.lang.NullPointerException when join Embedded classes
---------------------------------------------------------------------------------------------------
Key: HHH-4589
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4589
Project: Hibernate Core
Issue Type: Bug
Components: query-hql
Affects Versions: 3.3.2
Environment: Hibernate 3.3.2.GA, Java 6 (Sun), Linux, Mysql 5
Reporter: Rodrigo Carvalho Rezende
Attachments: hb-hql-join-embedded-bug.tar.gz
When I join a entity with a embedded class in HQL a null pointer exception is thrown.
See the stack trace:
Exception in thread "main" java.lang.NullPointerException
at org.hibernate.hql.ast.HqlSqlWalker.createFromJoinElement(HqlSqlWalker.java:371)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.joinElement(HqlSqlBaseWalker.java:3452)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3239)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3112)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:720)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:571)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:288)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:231)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:254)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1651)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:93)
at BugNullPointerException.main(BugNullPointerException.java:15)
I've isolated the behavior in an attached JSE (eclipse) project to be reproducible (pls, create the "hb_hql_join_embedded_bug" database)
Thanks, Rodrigo.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
16 years, 4 months
[Hibernate-JIRA] Created: (HSEARCH-306) Problem with composite key
by Mohit Khopkar (JIRA)
Problem with composite key
--------------------------
Key: HSEARCH-306
URL: http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-306
Project: Hibernate Search
Issue Type: Bug
Components: query
Affects Versions: 3.1.0.CR1
Reporter: Mohit Khopkar
Attachments: hibernate jira.zip
When a composite key is used and more than one results are expected , the values passed to the query are not in a proper expected order.
In the below query the parameters passed are (A00, A00),(A00, 1),(2,5) ....instead of the correct order which should be (A00,1) ,(A00,2), (A00,5)
(I have omitted the select part)..
..
where ((this_.key_client, this_.key_identifier) in ((?, ?), (?, ?), (?, ?)))
I tried to debug this issue and found that in the class org.hibernate.criterion.InExpression, the method getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) has 2 for loops , one for types and other for values. I get 2 types CustomType and LongType and so for each type it retrieves the value and adds it in the list in the order A00,A00,A00,1,2,5
I have attached the source code for your reference.
For more information, refer to the below topic on the hibernate forums:
http://forums.hibernate.org/viewtopic.php?t=992121&sid=16e54abb3dbc45d314...
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
16 years, 4 months
[Hibernate-JIRA] Created: (HHH-3164) "id in ..." with EmbeddedId and criteria API
by Bartosz Jablonski (JIRA)
"id in ..." with EmbeddedId and criteria API
--------------------------------------------
Key: HHH-3164
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3164
Project: Hibernate3
Issue Type: Bug
Components: query-criteria
Affects Versions: 3.2.6
Environment: hibrenate 3.2.5 hibernate-annotations 3.3.0, database - h2, postgresql, h2
Reporter: Bartosz Jablonski
Attachments: test.zip
This issue arised when I was debugging hibernate search, which wasn't retriving entities from query.
Problem is using query like 'entity.id in ...' with criteria api and embeddedId.
Let's say that we have classes:
@Entity
public class SomeEntity implements Serializable {
@Id
private SomeEntityId id;
(...)
}
@Embeddable
public class SomeEntityId implements Serializable {
private Integer id;
private Integer version;
(...)
}
In database there are rows:
(id,version)
1,11
1,12
10,21
10,22
10,23
Now I want to retrive rows with id (1,12) and (10,23) using Criteria API:
List ids = new ArrayList<SomeEntityId>(2);
ids.add( new SomeEntityId(1,12) );
ids.add( new SomeEntityId(10,23) );
Criteria criteria = session.createCriteria( SomeEntity.class );
Disjunction disjunction = Restrictions.disjunction();
disjunction.add( Restrictions.in( "id", ids ) );
criteria.add( Restrictions.in( "id", ids ) );
hibernate returns no rows, because it constructs query like this:
select this_.id as id0_0_, this_.version as version0_0_, this_.prop as prop0_0_ from SomeEntity this_ where (this_.id, this_.version) in ((1, 10), (12, 23))
instead of
select * from SomeEntity where (id, version) in ((1, 12), (10, 23))
As example I attached maven project which is using h2 database - just run class test.App
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
16 years, 4 months
[Hibernate-JIRA] Created: (HCANN-12) Metadata-annotations on jointables are unsupported
by Niklas Saers (JIRA)
Metadata-annotations on jointables are unsupported
--------------------------------------------------
Key: HCANN-12
URL: http://opensource.atlassian.com/projects/hibernate/browse/HCANN-12
Project: Hibernate Commons Annotations
Issue Type: New Feature
Environment: Hibernate 3.3, Spring 3, JDK 1.6, MySQL 5.0
Reporter: Niklas Saers
A jointable in Hibernate is expected to have only two fields, two foreign keys. However, this relationship often has metadata, such as when it was created, and can have discriminators, such as an enum saying what it belongs to. As requested, I've started with a forum post "https://forum.hibernate.org/viewtopic.php?f=1&t=1001044", and to get more input I've crossposted on StackOverflow: "http://stackoverflow.com/questions/1761901/multiple-manytomany-sets-from-...". The discriminator should be the easy task, but how to think about annotations on relationships is probably the underlying task.
The only solution I can think of with Hibernate right now is to make "relationship entities", but that would leave me with a bunch of poorly defined entities, rather than correctly described relationships.
Cheers
Nik
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
16 years, 4 months