in Education by
@Entity class A { @ManyToMany private List list; ... } @Entity class B { ... } I'd like to get list from A class using criteria (not sql query). Is it posible to do this? Projection in this case does not work. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Unfortunately, The Criteria only allows selecting the root entity, and not any joined entity. It would thus be easier if your ManyToMany was bidirectional. You could the use the criteria equivalent of select b from B b inner join b.as a where a = :theA If that's not an option, I think the only way is to use a subquery, and thus code the criteria equivalent to select b from B b where b.id in (select b2.id from A a inner join a.list b2 where a.id = :theAId) The code would thus look like this: Criteria c = session.createCriteria(B.class, "b"); DetachedCriteria dc = DetachedCriteria.forClass(A.class, "a"); dc.createAlias("a.list", "b2"); dc.add(Restrictions.eq("a.id", theA.getId())); dc.setProjection(Projections.property("b2.id")); c.add(Subqueries.propertyIn("b.id", dc));

Related questions

0 votes
    @Entity class A { @ManyToMany private List list; ... } @Entity class B { ... } I'd like to ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    Calling javax.persistence.criteria.Path.get(String name) fails for the simple class hierarchy detailed below. The ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jan 15, 2022 in Education by JackTerrance
0 votes
    What is the requirement for a Java object to become a Hibernate entity object?...
asked Feb 4, 2021 in Technology by JackTerrance
0 votes
    Define criteria in terms of Hibernate?...
asked Apr 14, 2021 in Technology by JackTerrance
0 votes
    I have a problem with Hibernate. In Short: How to configure a ManyToMany association with Hibernate when the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 21, 2022 in Education by JackTerrance
0 votes
    What is Many-to-Many association in Hibernate?...
asked Feb 4, 2021 in Technology by JackTerrance
0 votes
    What is One-to-Many association in Hibernate?...
asked Feb 4, 2021 in Technology by JackTerrance
0 votes
    I've searched stackoverflow for a proper solution on generating a many-to-many relationship, using EF Core, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 13, 2022 in Education by JackTerrance
0 votes
    How many constant values can the property type be represented? (a) 2 (b) 3 (c) 4 (d) 5 ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 22, 2021 in Education by JackTerrance
0 votes
    For which of the following criteria can Spring boot auto configuration be done? A. Presence of a System Property B. ... of a particular class in classpath E. All the options...
asked Nov 8, 2022 in Education by JackTerrance
0 votes
    What are the criteria for a regional party to get recognition? Please answer the above question....
asked Aug 14, 2022 in Education by JackTerrance
0 votes
    I'm using the Microsoft Access to do the SQL and is there any way for me to set the criteria for ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 3, 2022 in Education by JackTerrance
0 votes
    If we have 10 eigenvectors then we can have 10 neural nodes in input layer.If we have 5 output classes then we ... in 1 hidden layer? Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    The optical computers are increasingly accessing our real-world data to build products that show commercial value ... 50% Select the correct answer from above options...
asked Dec 6, 2021 in Education by JackTerrance
...