From 80ff6b4fe64bb69ae730a5db02084ea1b504f063 Mon Sep 17 00:00:00 2001 From: Stoty Date: Fri, 1 Feb 2019 15:05:03 +0100 Subject: [PATCH] HHH-13244 - setting hibernate.jpa.compliance.proxy=true and org.hibernate debug level to DEBUG breaks hibernate test case simplify test case --- .../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 0000000000..6423649fed --- /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; + } + + } + + +}