Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Neo4J - JPQL query on @ManyToOne not working
PostPosted: Fri May 08, 2015 1:26 pm 
Newbie

Joined: Fri May 08, 2015 1:10 pm
Posts: 1
Hello, I am trying to make a query (JPQL) in a relationship 'ManyToOne' and I'm a NullPointerException.

And the same can do via Cypher queries (createNativeQuery)

Code:
TypedQuery<DashboardItem> query = em.createQuery("from DashboardItem WHERE parent = :parentID ORDER BY id", DashboardItem.class);
query.setParameter("parentID", dashboard);


Quote:
Exception in thread "main" java.lang.NullPointerException
at org.hibernate.ogm.type.impl.ManyToOneType.getIdGridType(ManyToOneType.java:56)
at org.hibernate.ogm.type.impl.ManyToOneType.nullSafeSet(ManyToOneType.java:64)
at org.hibernate.ogm.datastore.neo4j.Neo4jDialect.getNamedParameterValuesConvertedByGridType(Neo4jDialect.java:621)
at org.hibernate.ogm.datastore.neo4j.Neo4jDialect.executeBackendQuery(Neo4jDialect.java:572)
at org.hibernate.ogm.query.impl.OgmQueryLoader$OgmQueryLoaderContext.executeQuery(OgmQueryLoader.java:150)


Using native queries runs smoothly
Code:
Query query = em.createNativeQuery("MATCH (n:DashboardItem)-[:parent]->(d:Dashboard) where d.id = {dashID} RETURN n ORDER BY n.id", DashboardItem.class);
query.setParameter("dashID", dashboard.getId());


Entities

Code:
@Entity
public class Dashboard {

    @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, fetch=FetchType.EAGER)
    private Set<DashboardItem> items = new HashSet<DashboardItem>();

}
@Entity
public class DashboardItem {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;

    @ManyToOne
    private Dashboard parent;
}



What am I doing wrong?


Top
 Profile  
 
 Post subject: Re: Neo4J - JPQL query on @ManyToOne not working
PostPosted: Tue May 12, 2015 5:00 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 294
Hi,
currently, in OGM, it is not possible to execute queries on associated entities.
This is something we want to improve, in the meanwhile, using a native query is the suggested alternative.

Cheers,
Davide


Top
 Profile  
 
 Post subject: Re: Neo4J - JPQL query on @ManyToOne not working
PostPosted: Tue May 12, 2015 5:18 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 386
Hi,

I have created https://hibernate.atlassian.net/browse/OGM-825 for this. It should be possible to support this query in some cases (if the id is stored on the "current" side of the association), for Neo4j also in general as we can traverse relationships.

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

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.