Spring Data JPA SubQuery

I´m in a situation where I have two entities, let´s say A and B, in B I have a relationship ManyToOne with A.But in A I dont have the oneToMany. I´m using Spring-Data repositories, and I was wondering If would be possible make a subQuery using Query annotation. So far I see some example of people using CriteriaQuery, but always with JOIN example, and in my case I need the other way around. I need to find all A´s if their id´s are not in B. Any good and elegant solutions?.

Answers


Just put @Query on your interface methods and write your JPQL there. Examples here: http://docs.oracle.com/javaee/7/tutorial/doc/persistence-querylanguage005.htm#BNBVL

e.g. SELECT DISTINCT a FROM A a WHERE NOT EXISTS (SELECT b FROM B b WHERE <<put your condition here>>)


You can use NamedNativeQuery of JPA or custom pojo class (with constructor to populate all your required field) but in this case you will get array of object and you have to fech your records from object array.


Need Your Help

Indexing json on Solr, it indexed as a List instead of as an item

json solr indexing solr4

I'm trying to index a JSON file in Solr and it works, but i don't understant why Solr is indexing elements as an array instead of an element.

How to create onpopstate event on click back and forward button

jquery ajax history

I have created a jquery ajax code to display a content using pushstate, it works good but when I click on back and forward button the content doesn't change again. How to create event onpopstate in...