Sum with one to many Spring Data JPA -


I am trying to get an amount with multiple relationships, shown by the following relationships (shown Gone parents only):

  @tainty @table (name = "parent") Serializable to the public class parents {Private Static Finals Long SerialsUID = 7348332185233715983L; @ Id @basic (optional = false) @ column (name = "ParisID") private long parent id; @OneToMany @JoinColumn (name = "child", referenced column name = "PARENT_ID") private list & lt; Child & gt; children; @forumula ("Choose from children (select height)") Private biscuitkle totalhite}  

This is no restriction and even with static restrictions it is also very easy. I'm having trouble when children's lists are dynamically restricted.

In my case, I am using Spring Data and JPA. I am using the specifications to restrict children and am receiving the appropriate list of children, but it is obvious that this amount is still for unrestricted children, because nobody is a section in the @ Formula tag.

I do not want it to be repeated in the list in Java for performance reasons and because the results are on the page, the amount is not of paged results but from all the results.

I'm new to Spring Data / JPA. Historically, I can dynamically create this query or use the hibernate parameter. I'm running a completley different query to calculate it. It is not necessary that I am using @formula annotation because there is only one group per call. In the Hibernate Framework, I could just tell the selection segment as "yoga (field)" and could construct the criteria. In the Spring Data / JPA Framework, I can create specifications covering the criteria, but I do not know how to manipulate the selected portion of the query because it starts typing the unit on such a criterion.

Using @notation on the repository works as its query if I know which field to restrict, but often the field is zero and the query is neglected for 8 potential Are there areas, except me with 256 possible combinations (2 ^ 8)

>

You have tried in JPQ

  Select an amount from the parent (D. high) a.children d   

If you do not want to select the amount from the parent (D. Heights) join in a left. A.children d I think that you have other questions on how it depends on the properties to filter, I mean if you need a statement with many combinations is.

If you do not try to use the list and add to the list, you want to implement all those predictions that you want based on the combination. Example

Create a query

  CriteriaBuilder cb = em.getCriteriaBuilder (); Criterion cq = cb.createQuery (double class); The root of the & lt; Parent & gt; Root = cq.from (parent.class) & lt; Parent, child & gt; Included = cq.join (("children")); Cq.select (CB & lt; double & gt; amount (join.get ("height"));  

Make a list of predictions

  list & lt; Predicates & gt; List ofFreadidates = New Arrestists & lt; Predicates & gt; (); If (property1! = Null & amp;! "" Equals (property1) {PatameterExpression & lt; string> gt = pb.parameter (String.class, "valueOfproperty1") listOfpredicates.add (cb.equal (join.get) ("Property1"), p);}  

then add to criterion

  if (listOfPredicates.size () == 1) cq.where ( ListOfPedicates .get (0)) and cq.where (cb.and (listOfPredicates.toArray (new certified [0]));  

Finally execute queries.

  typed query> double> gt = em.createQuery (cq); q.getResultList ();  

This is dynamic with any combination Form your query.


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -