-->
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: Mapped Collections Broken in 3.6.2
PostPosted: Thu Apr 07, 2011 6:02 pm 
Newbie

Joined: Thu Apr 07, 2011 5:54 pm
Posts: 1
I have an Employe entity with a mapped collection for phone numbers

Code:
@ElementCollection(fetch=FetchType.EAGER)
@CollectionTable(name="emp_phone")
@MapKeyColumn(name="phone_type")
@Column(name="phone_num")
private Map<String, String> phoneNumbers;


When I try to create a criteria API over it:

Code:
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Employee> criteria = builder.createQuery(Employee.class);
Root<Employee> employeeRoot = criteria.from(Employee.class);
criteria.select(employeeRoot);
MapJoin<Employee, String, String> phoneRoot = employeeRoot.joinMap("phoneNumbers");
criteria.where(builder.equal(phoneRoot.key(), "HOME"));
           
System.out.println(entityManager.createQuery(criteria).getResultList());



I get a NullPointerException

Code:
Exception in thread "main" java.lang.RuntimeException: java.lang.NullPointerException
   at com.dalorzo.Main.main(Main.java:62)
Caused by: java.lang.NullPointerException
   at org.hibernate.ejb.criteria.path.AbstractPathImpl.prepareAlias(AbstractPathImpl.java:246)
   at org.hibernate.ejb.criteria.path.AbstractPathImpl.render(AbstractPathImpl.java:253)
   at org.hibernate.ejb.criteria.predicate.ComparisonPredicate.render(ComparisonPredicate.java:173)
   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:223)
   at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:441)
   at com.dalorzo.Main.main(Main.java:56)


The error does not happen in EclipseLink 2.0

I also tried to implement it using JPQL query, like this:

Code:
String query = "SELECT e FROM Employee e JOIN e.phoneNumbers p WHERE KEY(p) IN ('HOME')";
System.out.println(entityManager.createQuery(query, Employee.class).getResultList());


I get a SQLGrammarException because this is the SQL being generated by Hibernate:

Code:
select
        employee0_.id as id0_,
        employee0_.name as name0_
    from
        Employee employee0_
    inner join
        emp_phone phonenumbe1_
            on employee0_.id=phonenumbe1_.Employee_id
    where
        KEY(phonenumbe1_.phone_num) in (
            'HOME'
        )


This is the exception

Code:
Exception in thread "main" java.lang.RuntimeException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
   at com.dalorzo.Main.main(Main.java:62)
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
   at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1214)
   at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1147)
   at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:255)
   at com.dalorzo.Main.main(Main.java:46)
Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
   at org.hibernate.loader.Loader.doList(Loader.java:2536)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
   at org.hibernate.loader.Loader.list(Loader.java:2271)
   at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:452)
   at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
   at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
   at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:246)
   ... 1 more
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 'KEY(phonenumbe1_.phone_num) in ('HOME')' at line 1
   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
   at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
   at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
   at com.mysql.jdbc.Util.getInstance(Util.java:381)
   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
   at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
   at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
   at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
   at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)
   at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1885)
   at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
   at org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
   at org.hibernate.loader.Loader.doQuery(Loader.java:802)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
   at org.hibernate.loader.Loader.doList(Loader.java:2533)
   ... 9 more


Any thoughts?


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.