SELECT NEW () with a many-in-one collection inside the constructor - HQL

It seems that I did not find the answer to what I refuse to accept as "Impossible" :)

Here is my HQL query: "SELECT new TestTable (t.id, t.param1, t.param2, t.param3, stps) FROM TestTable t left join t.steps as stps WHERE t.someObj.id IN (: someObjIds)"

TestTable has the following consturtor: public TestTable (Integer param1, Integer param2, Date param3, Date param4, Set steps)

I tried to use Collection in constructor instead of Set, but it did not work, the constructor will receive only the first element from the collection as a parameter, and not the entire collection, as I expected.

in the request, I also tried to use the left connection fetch t.steps, tried without the left connection at all, tried to surround the "stps" parameter in the constructor with "elements" as follows: elements (stps)

but it didn’t work out ... the reason I am doing this is because TestTable is very large and has many columns and associations, but in this case I want only 4 columns and one collection. when a single request can return up to 400,000 objects, it becomes necessary.

any ideas anyone ??? (by the way, my name is Tomer)

+3
source share
2 answers

Your request may work without the "new" constructor, but it does not give you what you expect.

t.id, t.param1, t.param2, t.param3, [ ] - join to steps.

: -, , TestTable. -

List<TestTable> resultList = "select new TestTable(t.id,t.param1,t.param2,t.param3) from TestTable where
                      t.someObj.id in (:someObjId)"

, TestTable.

for (TestTable tt : resultList) {
    List<Steps> stepList = "select st from Steps st where st.testTable.id = :ttId";
    tt.setSteps(stepList);
}
+4
+2

Source: https://habr.com/ru/post/1780378/


All Articles