[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-4881) restrict polymorphic query results

Gail Badner (JIRA) noreply at atlassian.com
Mon Jan 10 23:14:05 EST 2011


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-4881?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=39552#action_39552 ] 

Gail Badner commented on HHH-4881:
----------------------------------

Is this still an issue using 3.6.0?

> restrict polymorphic query results
> ----------------------------------
>
>                 Key: HHH-4881
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4881
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.5.0-Beta-4
>         Environment: Hibernate 3.5.0-Beta-4, MySQL 5.1 Glassfish v3
>            Reporter: Domenico Loiacono
>
> I'm using JPA 2.0, Hibernate 3.5.0-Beta4, MySQL 5.1 on Glassfish v3.
> I want to limit the polymorphic query results using JPA 2.0 syntax (TYPE) :
> SELECT e FROM Employee e WHERE TYPE(e) IN (FullTime, Executive)
> but it seems that Hibernate 3.5.0-Beta4 doesn't support this syntax because in the generated sql query the 'type' keyword remains unmapped and MySQL throws an Exception:
> Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(type(employee0_.id) in (5))' at line 1
> So I tried with Criteria API:
> CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder(); 
> CriteriaQuery<Employee> criteria = criteriaBuilder.createQuery(Employee.class);
> Root<Employee> employee= criteria.from(Employee.class);
> criteria.where(employee.type().in(FullTime.class,Executive.class));
> But I received an Exception:
> Caused by: java.lang.IllegalArgumentException: Unexpected call on EntityTypeExpression#render
> at org.hibernate.ejb.criteria.expression.PathTypeExpression.render(PathTypeExpression.java:48)
> at org.hibernate.ejb.criteria.predicate.InPredicate.render(InPredicate.java:164)
> at org.hibernate.ejb.criteria.QueryStructure.render(QueryStructure.java:258)
> at org.hibernate.ejb.criteria.CriteriaQueryImpl.render(CriteriaQueryImpl.java:340)
> at org.hibernate.ejb.criteria.CriteriaQueryCompiler.compile(CriteriaQueryCompiler.java:150)
> at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:416)
> at com.sun.enterprise.container.common.impl.EntityManagerWrapper.createQuery(EntityManagerWrapper.java:489)
> So I opened the PathTypeExpression class and in the render method I saw :
> public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
> // todo : is it valid for this to get rendered into the query itself?
> throw new IllegalArgumentException( "Unexpected call on EntityTypeExpression#render" );
> }
> Then I switched to use Hibernate custom query syntax (class) :
> SELECT e FROM Employee e WHERE (e.class) IN (FullTime, Executive)
> Ok this works fine.
> But when I add a join with another entity (Department) that has the same TABLE_PER_CLASS inheritance strategy of entity Employee, I have a new problem:
> SELECT e FROM Employee e JOIN e.departments d WHERE d.code = 'D1' and (e.class) IN (FullTime, Executive)
> GRAVE: Column 'clazz_' in where clause is ambiguous
> Caused by: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not execute query

-- 
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.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list