From 8524676bd36d50507fff3501755e2d16ec565c99 Mon Sep 17 00:00:00 2001 From: Stoty Date: Fri, 1 Feb 2019 15:05:03 +0100 Subject: [PATCH 1/3] HHH-13244 - setting hibernate.jpa.compliance.proxy=true and org.hibernate debug level to DEBUG breaks hibernate test case simplify test case (cherry picked from commit 80ff6b4fe64bb69ae730a5db02084ea1b504f063) --- .../jpa/test/JpaProxyComplianceWithDebug.java | 228 ++++++++++++++++++ 1 file changed, 228 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/jpa/test/JpaProxyComplianceWithDebug.java diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/JpaProxyComplianceWithDebug.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/JpaProxyComplianceWithDebug.java new file mode 100644 index 000000000000..6423649fed84 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/JpaProxyComplianceWithDebug.java @@ -0,0 +1,228 @@ +package org.hibernate.jpa.test; + +import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; + +import java.io.Serializable; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +import org.apache.log4j.Level; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; +import org.hibernate.cfg.AvailableSettings; +import org.hibernate.testing.TestForIssue; +import org.junit.Before; +import org.junit.Test; + +@TestForIssue(jiraKey = "HHH-13244") +public class JpaProxyComplianceWithDebug extends BaseEntityManagerFunctionalTestCase { + + @Override + protected void addConfigOptions(Map options) { + options.put( + AvailableSettings.JPA_PROXY_COMPLIANCE, + Boolean.TRUE); + } + + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] { + MvnoBillingAgreement.class, + MvnoOpcio.class, + }; + } + + @Before + public void setUp() { + List opciok = Arrays.asList(2008, 2010, 2012, 2014, 2015, 2026, 2027, 2103, 2110, 2145, 992068, 992070); + + doInJPA(this::entityManagerFactory, entityManager -> { + + MvnoBillingAgreement ba = new MvnoBillingAgreement(); + ba.setId(1); + ba.setName("1"); + entityManager.persist(ba); + + for (int opcioId : opciok) { + MvnoOpcio o = new MvnoOpcio(); + o.setId(opcioId); + o.setMegnevezes(Integer.toString(opcioId)); + o.getMvnoBillingAgreementekDefaultOpcioja().add(ba); + ba.getMvnoDefaultUniverzalisOpcioi().add(o); + entityManager.persist(o); + } + + ba.setBehajtasEgyiranyusitasOpcio(entityManager.find(MvnoOpcio.class, 2026)); + ba.setBehajtasFelfuggesztesOpcio(entityManager.find(MvnoOpcio.class, 992070)); + ba.setHotlimitEmeltDijasBarOpcio(entityManager.find(MvnoOpcio.class, 2145)); + + }); + } + + + @Test + @TestForIssue(jiraKey = "HHH-13244") + public void testJpaComplianceProxyWithDebug() { + + //This could be replaced with setting the root logger level, or the "org.hibernate" logger to debug. + //These are simply the narrowest log settings that trigger the bug + Logger entityLogger = LogManager.getLogger("org.hibernate.internal.util.EntityPrinter"); + Logger listenerLogger = LogManager.getLogger("org.hibernate.event.internal.AbstractFlushingEventListener"); + + Level oldEntityLogLevel = entityLogger.getLevel(); + Level oldListenerLogLevel = listenerLogger.getLevel(); + + entityLogger.setLevel((Level) Level.DEBUG); + listenerLogger.setLevel((Level) Level.DEBUG); + try { + doInJPA(this::entityManagerFactory, entityManager -> { + entityManager.find(MvnoBillingAgreement.class, 1); + }); + } finally { + entityLogger.setLevel(oldEntityLogLevel); + listenerLogger.setLevel(oldListenerLogLevel); + } + + } + + @Entity + @Table(name = "mvno_billing_agreement") + public static class MvnoBillingAgreement implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + private int id; + + private String name; + + @ManyToMany + @JoinTable( + name = "mvno_billing_agreement_default_univerzalis_opcio", joinColumns = { + @JoinColumn(name = "billing_agreement_id") + }, + inverseJoinColumns = { + @JoinColumn(name = "univerzalis_opcio_id") + }) + private Set mvnoDefaultUniverzalisOpcioi = new HashSet<>(); + + @JoinColumn(name = "behajtas_egyiranyusitas_opcio_id") + @ManyToOne(fetch = FetchType.LAZY) + private MvnoOpcio behajtasEgyiranyusitasOpcio; + + @JoinColumn(name = "behajtas_felfuggesztes_opcio_id") + @ManyToOne(fetch = FetchType.LAZY) + private MvnoOpcio behajtasFelfuggesztesOpcio; + + @JoinColumn(name = "hotlimit_emeltdijas_bar_opcio_id") + @ManyToOne(fetch = FetchType.LAZY) + private MvnoOpcio hotlimitEmeltDijasBarOpcio; + + public MvnoBillingAgreement() {} + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Set getMvnoDefaultUniverzalisOpcioi() { + return this.mvnoDefaultUniverzalisOpcioi; + } + + public void setMvnoDefaultUniverzalisOpcioi(Set mvnoDefaultUniverzalisOpcioi) { + this.mvnoDefaultUniverzalisOpcioi = mvnoDefaultUniverzalisOpcioi; + } + + public MvnoOpcio getBehajtasEgyiranyusitasOpcio() { + return this.behajtasEgyiranyusitasOpcio; + } + + public void setBehajtasEgyiranyusitasOpcio(MvnoOpcio behajtasEgyiranyusitasOpcio) { + this.behajtasEgyiranyusitasOpcio = behajtasEgyiranyusitasOpcio; + } + + public MvnoOpcio getBehajtasFelfuggesztesOpcio() { + return this.behajtasFelfuggesztesOpcio; + } + + public void setBehajtasFelfuggesztesOpcio(MvnoOpcio behajtasFelfuggesztesOpcio) { + this.behajtasFelfuggesztesOpcio = behajtasFelfuggesztesOpcio; + } + + public MvnoOpcio getHotlimitEmeltDijasBarOpcio() { + return this.hotlimitEmeltDijasBarOpcio; + } + + public void setHotlimitEmeltDijasBarOpcio(MvnoOpcio hotlimitEmeltDijasBarOpcio) { + this.hotlimitEmeltDijasBarOpcio = hotlimitEmeltDijasBarOpcio; + } + + } + + @Entity + @Table(name = "mvno_opcio") + public static class MvnoOpcio implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + private int id; + + @Column(name = "megnevezes") + private String megnevezes; + + @ManyToMany(mappedBy = "mvnoDefaultUniverzalisOpcioi") + private Set mvnoBillingAgreementekDefaultOpcioja = new HashSet<>(); + + public MvnoOpcio() {} + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public String getMegnevezes() { + return this.megnevezes; + } + + public void setMegnevezes(String megnevezes) { + this.megnevezes = megnevezes; + } + + public Set getMvnoBillingAgreementekDefaultOpcioja() { + return this.mvnoBillingAgreementekDefaultOpcioja; + } + + public void setMvnoBillingAgreementekDefaultOpcioja(Set mvnoBillingAgreementekDefaultOpcioja) { + this.mvnoBillingAgreementekDefaultOpcioja = mvnoBillingAgreementekDefaultOpcioja; + } + + } + + +} From 108322df5d0ccee553880534bfb27303205e3f98 Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Mon, 4 Feb 2019 13:51:28 -0800 Subject: [PATCH 2/3] HHH-13244 : Fix EntityPrinter to log "" for uninitalized proxies (cherry picked from commit 36fc1ad35e094df3aa42abe3a29c1798c1543414) --- .../org/hibernate/internal/util/EntityPrinter.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/EntityPrinter.java b/hibernate-core/src/main/java/org/hibernate/internal/util/EntityPrinter.java index f4ac35f059d3..09d2649b439a 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/EntityPrinter.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/util/EntityPrinter.java @@ -9,6 +9,7 @@ import java.util.HashMap; import java.util.Map; +import org.hibernate.Hibernate; import org.hibernate.HibernateException; import org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer; import org.hibernate.engine.spi.EntityKey; @@ -61,9 +62,16 @@ public String toString(String entityName, Object entity) throws HibernateExcepti Object[] values = entityPersister.getPropertyValues( entity ); for ( int i = 0; i < types.length; i++ ) { if ( !names[i].startsWith( "_" ) ) { - String strValue = values[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY ? - values[i].toString() : - types[i].toLoggableString( values[i], factory ); + final String strValue; + if ( values[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY ) { + strValue = values[i].toString(); + } + else if ( !Hibernate.isInitialized( values[i] ) ) { + strValue = ""; + } + else { + strValue = types[i].toLoggableString( values[i], factory ); + } result.put( names[i], strValue ); } } From 9b8168d4ed18ae1f976685b83efc22502e764387 Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Wed, 6 Feb 2019 16:55:09 -0800 Subject: [PATCH 3/3] HHH-13244 : add header to test; shorten table/column names to avoid oracle failure (cherry picked from commit 0720b2b376ccfe6960db7aa81cddace51cef8f19) --- .../jpa/test/JpaProxyComplianceWithDebug.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/JpaProxyComplianceWithDebug.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/JpaProxyComplianceWithDebug.java index 6423649fed84..a619e6a9e15d 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/JpaProxyComplianceWithDebug.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/JpaProxyComplianceWithDebug.java @@ -1,3 +1,9 @@ +/* + * 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.jpa.test; import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; @@ -110,7 +116,7 @@ public static class MvnoBillingAgreement implements Serializable { @ManyToMany @JoinTable( - name = "mvno_billing_agreement_default_univerzalis_opcio", joinColumns = { + name = "mvnobillagr_def_univerzalis", joinColumns = { @JoinColumn(name = "billing_agreement_id") }, inverseJoinColumns = { @@ -118,15 +124,15 @@ public static class MvnoBillingAgreement implements Serializable { }) private Set mvnoDefaultUniverzalisOpcioi = new HashSet<>(); - @JoinColumn(name = "behajtas_egyiranyusitas_opcio_id") + @JoinColumn(name = "egyiranyusitas_opcio_id") @ManyToOne(fetch = FetchType.LAZY) private MvnoOpcio behajtasEgyiranyusitasOpcio; - @JoinColumn(name = "behajtas_felfuggesztes_opcio_id") + @JoinColumn(name = "felfuggesztes_opcio_id") @ManyToOne(fetch = FetchType.LAZY) private MvnoOpcio behajtasFelfuggesztesOpcio; - @JoinColumn(name = "hotlimit_emeltdijas_bar_opcio_id") + @JoinColumn(name = "emeltdijas_bar_opcio_id") @ManyToOne(fetch = FetchType.LAZY) private MvnoOpcio hotlimitEmeltDijasBarOpcio;