From 900da12419e05d8770a4ff691e3a2324914f44f0 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Mon, 12 Oct 2020 13:27:59 +0100 Subject: [PATCH] HHH-14251 Add test for issue --- .../hql/UpdateEntityWithEmbeddedTest.java | 139 ++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/test/hql/UpdateEntityWithEmbeddedTest.java diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/UpdateEntityWithEmbeddedTest.java b/hibernate-core/src/test/java/org/hibernate/test/hql/UpdateEntityWithEmbeddedTest.java new file mode 100644 index 0000000000..e789f809d5 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/hql/UpdateEntityWithEmbeddedTest.java @@ -0,0 +1,139 @@ +/* + * 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.hql; + +import javax.persistence.Embeddable; +import javax.persistence.Embedded; +import javax.persistence.Entity; +import javax.persistence.Id; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * @author Andrea Boriero + */ +@TestForIssue(jiraKey = "HHH-14251") +public class UpdateEntityWithEmbeddedTest extends BaseCoreFunctionalTestCase { + + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] { Company.class }; + } + + @Before + public void setUp() { + inTransaction( + session -> { + Logo logo = new Logo( "logo1", "png" ); + Company company = new Company( 1l, logo ); + session.save( company ); + } + ); + } + + @After + public void tearDown() { + inTransaction( + session -> { + session.createQuery( "delete from Company" ).executeUpdate(); + } + ); + } + + @Test + public void testUpdate() { + inTransaction( + session -> { + Logo logo = new Logo( "logo2", "png" ); + session.createQuery( "UPDATE Company c SET c.logo = :logo" ) + .setParameter( "logo", logo ) + .executeUpdate(); + } + ); + } + + @Test + public void testUpdate2() { + inTransaction( + session -> { + session.createQuery( + "UPDATE Company c SET c.logo.fileName = :filename, c.logo.fileExtension = :fileExtension" ) + .setParameter( "filename", "logo2" ) + .setParameter( "fileExtension", "png" ) + .executeUpdate(); + } + ); + } + + @Entity(name = "Company") + public static class Company { + @Id + private Long id; + + @Embedded + private Logo logo; + + public Company() { + } + + public Company(Long id, Logo logo) { + this.id = id; + this.logo = logo; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Logo getLogo() { + return logo; + } + + public void setLogo(Logo logo) { + this.logo = logo; + } + } + + @Embeddable + public static class Logo { + String fileName; + + String fileExtension; + + public Logo() { + } + + public Logo(String fileName, String fileExtension) { + this.fileName = fileName; + this.fileExtension = fileExtension; + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public String getFileExtension() { + return fileExtension; + } + + public void setFileExtension(String fileExtension) { + this.fileExtension = fileExtension; + } + } +}