diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/BasicProxyFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/BasicProxyFactoryImpl.java index ef080f4eff..581a3efd37 100644 --- a/hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/BasicProxyFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/BasicProxyFactoryImpl.java @@ -26,6 +26,7 @@ public class BasicProxyFactoryImpl implements BasicProxyFactory { private final Class proxyClass; + @SuppressWarnings("unchecked") public BasicProxyFactoryImpl(Class superClass, Class[] interfaces, ByteBuddyState bytebuddy) { if ( superClass == null && ( interfaces == null || interfaces.length < 1 ) ) { throw new AssertionFailure( "attempting to build proxy without any superclass or interfaces" ); @@ -39,7 +40,7 @@ public class BasicProxyFactoryImpl implements BasicProxyFactory { .implement( interfaces == null ? NO_INTERFACES : interfaces ) .defineField( ProxyConfiguration.INTERCEPTOR_FIELD_NAME, ProxyConfiguration.Interceptor.class, Visibility.PRIVATE ) .method( ElementMatchers.isVirtual().and( ElementMatchers.not( ElementMatchers.isFinalizer() ) ) ) - .intercept( MethodDelegation.toField( ProxyConfiguration.INTERCEPTOR_FIELD_NAME ) ) + .intercept( MethodDelegation.to( ProxyConfiguration.InterceptorDispatcher.class ) ) .implement( ProxyConfiguration.class ) .intercept( FieldAccessor.ofField( ProxyConfiguration.INTERCEPTOR_FIELD_NAME ).withAssigner( Assigner.DEFAULT, Assigner.Typing.DYNAMIC ) ) .make() diff --git a/hibernate-core/src/test/java/org/hibernate/test/component/proxy/Adult.java b/hibernate-core/src/test/java/org/hibernate/test/component/proxy/Adult.java new file mode 100644 index 0000000000..027f8c4fe4 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/component/proxy/Adult.java @@ -0,0 +1,21 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.test.component.proxy; + +import javax.persistence.Entity; + +@Entity +public class Adult extends Person { + + public Adult() { + someInitMethod(); + } + + @Override + public void someInitMethod() { + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/component/proxy/ComponentBasicProxyTest.java b/hibernate-core/src/test/java/org/hibernate/test/component/proxy/ComponentBasicProxyTest.java new file mode 100644 index 0000000000..59debe8ff6 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/component/proxy/ComponentBasicProxyTest.java @@ -0,0 +1,47 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.test.component.proxy; + +import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; + +import java.util.List; + +import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; +import org.hibernate.testing.TestForIssue; +import org.junit.Test; + +/** + * @author Guillaume Smet + * @author Oliver Libutzki + */ +public class ComponentBasicProxyTest extends BaseEntityManagerFunctionalTestCase { + + @Override + protected Class[] getAnnotatedClasses() { + return new Class[]{ + Person.class, Adult.class + }; + } + + @Test + @TestForIssue(jiraKey = "HHH-12786") + public void testBasicProxyingWithProtectedMethodCalledInConstructor() { + doInJPA( this::entityManagerFactory, entityManager -> { + Adult adult = new Adult(); + adult.setName( "Arjun Kumar" ); + entityManager.persist( adult ); + } ); + + doInJPA( this::entityManagerFactory, entityManager -> { + List adultsCalledArjun = entityManager + .createQuery( "SELECT a from Adult a WHERE a.name = :name", Adult.class ) + .setParameter( "name", "Arjun Kumar" ).getResultList(); + Adult adult = adultsCalledArjun.iterator().next(); + entityManager.remove( adult ); + } ); + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/component/proxy/Person.java b/hibernate-core/src/test/java/org/hibernate/test/component/proxy/Person.java new file mode 100644 index 0000000000..7d74686429 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/component/proxy/Person.java @@ -0,0 +1,68 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.test.component.proxy; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.IdClass; +import javax.persistence.Table; + +@Entity +@Table(name = "person") +@IdClass(PersonId.class) +public abstract class Person { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id") + private int id; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "clientId") + private int clientId; + + @Column(name = "name") + private String name; + + @Column(name = "title") + private String title; + + public Person() { + someInitMethod(); + } + + public void someInitMethod() { + } + + public int getId() { + return id; + } + + public int getClientId() { + return clientId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getTitle(String name) { + return title; + } + + public void setTitle(String title) { + this.title = title; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/component/proxy/PersonId.java b/hibernate-core/src/test/java/org/hibernate/test/component/proxy/PersonId.java new file mode 100644 index 0000000000..a1ce7edb2a --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/component/proxy/PersonId.java @@ -0,0 +1,42 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.test.component.proxy; + +import java.io.Serializable; + +@SuppressWarnings("all") +public class PersonId implements Serializable { + + private int id; + + private int clientId; + + public PersonId() { + } + + public PersonId(int aId, int aClientId) { + setId( aId ); + setClientId( aClientId ); + } + + public int getId() { + return id; + } + + public void setId(int aId) { + this.id = aId; + } + + public int getClientId() { + + return clientId; + } + + public void setClientId(int aClientId) { + clientId = aClientId; + } +}