in Education by
Calling javax.persistence.criteria.Path.get(String name) fails for the simple class hierarchy detailed below. The call succeeds if @IdClass and 2nd id field (i.e. id2) are removed. Anyone know why this is so. Does this mean it is not possible to query on a single id field where that id field forms part of a composite key? failing call is: Path path = entity.get(name); private static final EntityManager em; private final CriteriaBuilder cb = em.getCriteriaBuilder(); private final CriteriaQuery query = cb.createQuery(Y.class); private final Root entity = query.from(Y.class); static { Map properties = new HashMap(); // initialise properties appropriately EntityManagerFactory emf = Persistence.createEntityManagerFactory("test", properties); em = emf.createEntityManager(); } interface PK { Object getPK(); } public static class YPK implements Serializable { int id; int id2; YPK(int id, int id2) { } // Override hashCode() and equals() appropriately } @IdClass(YPK.class) @Entity public static class Y implements Serializable, PK { @Id int id; @Id int id2; protected Y() { } public Y(int id) { this.id = id; } @Override public Object getPK() { return id; } } @Test public void simpleTest() { List yy = new ArrayList(); Y yX1 = new Y(5); yy.add(yX1); Y yX2 = new Y(6); yy.add(yX2); saveItems(yy); String name = "id"; Path path = entity.get(name); Predicate restriction = cb.conjunction(); restriction = cb.and(restriction, cb.and(new Predicate[]{cb.equal(path, 5)})); TypedQuery tq = em.createQuery(this.query); Y result = null; try { result = tq.getSingleResult(); } catch (NoResultException e) { } assertNotNull(result); } 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)

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
    @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
    Define criteria in terms of Hibernate?...
asked Apr 14, 2021 in Technology by JackTerrance
0 votes
    What are the key components of persistence API in EJB?...
asked Nov 7, 2020 in Technology by JackTerrance
0 votes
    I'm trying to implement continuous integration and continuous deployment to my DEV Azure App Service. I'm ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    If an attribute of a composite key is dependent on an attribute of the other composite key, a ... , Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    A relation is in ____________ if an attribute of a composite key is dependent on an attribute of other ... for Decomposition topic in division Normalization of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
0 votes
    When curl of a path is zero, the field is said to be conservative. State True/False. ... theory proposed by,electromagnetic theory engineering physics,electromagnetic theory nptel...
asked Nov 11, 2021 in Education by JackTerrance
0 votes
    What are the key components of Hibernate?...
asked Apr 14, 2021 in Technology by JackTerrance
0 votes
    If the probabilities for A to fail in an examination is 0.2 and that for B is 0.3, then the probability that either A ... C. ≤ .5 D. 0 Select the correct answer from above options...
asked Nov 20, 2021 in Education by JackTerrance
0 votes
    If the probabilities for A to fail in an examination is 0.2 and that for B is 0.3, then the probability that either A ... C. ≤0.5 D. 0 Select the correct answer from above options...
asked Nov 15, 2021 in Education by JackTerrance
0 votes
    If the probability for A to fail in an examination is 0.2 and that for B is 0.3, then the probability that either A ... 0.50 (D) 0.94 Select the correct answer from above options...
asked Nov 13, 2021 in Education by JackTerrance
...