|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 | + * Copyright Red Hat Inc. and Hibernate Authors |
| 4 | + */ |
| 5 | +package org.hibernate.orm.test.mapping.hhh18829; |
| 6 | + |
| 7 | +import org.hibernate.testing.orm.junit.DomainModel; |
| 8 | +import org.hibernate.testing.orm.junit.JiraKey; |
| 9 | +import org.hibernate.testing.orm.junit.SessionFactory; |
| 10 | +import org.hibernate.testing.orm.junit.SessionFactoryScope; |
| 11 | +import org.junit.jupiter.api.BeforeAll; |
| 12 | +import org.junit.jupiter.api.Test; |
| 13 | + |
| 14 | +import java.lang.reflect.InvocationTargetException; |
| 15 | + |
| 16 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 17 | + |
| 18 | +@DomainModel(annotatedClasses = EmployeeWithoutIdClass.class) |
| 19 | +@JiraKey(" HHH-18829") |
| 20 | +@SessionFactory |
| 21 | +public class HHH18829Test { |
| 22 | + |
| 23 | + @BeforeAll |
| 24 | + void setUp(SessionFactoryScope sessionFactoryScope) { |
| 25 | + sessionFactoryScope.inTransaction( sess -> { |
| 26 | + final var one = new EmployeeWithoutIdClass(); |
| 27 | + one.empName = "John Doe"; |
| 28 | + one.empId = 1; |
| 29 | + one.address = "10 Downing Street, SW1A 2AA"; |
| 30 | + sess.persist( one ); |
| 31 | + |
| 32 | + final var two = new EmployeeWithoutIdClass(); |
| 33 | + two.empName = "Dave Default"; |
| 34 | + two.empId = 1; |
| 35 | + two.address = "1600 Pennsylvania Avenue"; |
| 36 | + sess.persist( two ); |
| 37 | + } ); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void test(SessionFactoryScope sessionFactoryScope) |
| 42 | + throws ClassNotFoundException, InvocationTargetException, InstantiationException, IllegalAccessException { |
| 43 | + final var idClass = Class.forName( EmployeeWithoutIdClass.class.getName() + "_$Id" ); |
| 44 | + final var id = idClass.getConstructors()[0].newInstance( 1, "John Doe" ); |
| 45 | + final var employees = sessionFactoryScope.fromSession( |
| 46 | + sess -> sess.createQuery( "from EmployeeWithoutIdClass where id=:id", EmployeeWithoutIdClass.class ).setParameter( "id", id ) |
| 47 | + .getResultList() |
| 48 | + ); |
| 49 | + assertEquals( 1, employees.size() ); |
| 50 | + assertEquals( "10 Downing Street, SW1A 2AA", employees.get( 0 ).address ); |
| 51 | + } |
| 52 | +} |
0 commit comments