diff --git a/hibernate-core/src/test/java/org/hibernate/test/jpa/MapContent.java b/hibernate-core/src/test/java/org/hibernate/test/jpa/MapContent.java new file mode 100644 index 0000000000..3cfc573a45 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/jpa/MapContent.java @@ -0,0 +1,28 @@ +package org.hibernate.test.jpa; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.ManyToOne; + +@Entity +public class MapContent { + + @Id + private Long id; + @ManyToOne(optional = false) + private Relationship relationship; + + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + public Relationship getRelationship() { + return relationship; + } + public void setRelationship(Relationship relationship) { + this.relationship = relationship; + } + +} \ No newline at end of file diff --git a/hibernate-core/src/test/java/org/hibernate/test/jpa/MapOwner.java b/hibernate-core/src/test/java/org/hibernate/test/jpa/MapOwner.java new file mode 100644 index 0000000000..69c1e13469 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/jpa/MapOwner.java @@ -0,0 +1,35 @@ +package org.hibernate.test.jpa; + +import java.util.Map; + +import javax.persistence.CascadeType; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.MapKey; +import javax.persistence.OneToMany; + +@Entity +public class MapOwner { + + @Id + private Long id; + + @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + @MapKey(name = "relationship") + private Map contents; + + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + public Map getContents() { + return contents; + } + public void setContents(Map contents) { + this.contents = contents; + } + +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/jpa/Relationship.java b/hibernate-core/src/test/java/org/hibernate/test/jpa/Relationship.java new file mode 100644 index 0000000000..4a96a45b59 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/jpa/Relationship.java @@ -0,0 +1,26 @@ +package org.hibernate.test.jpa; + +import javax.persistence.Entity; +import javax.persistence.Id; + +@Entity +public class Relationship { + + @Id + private Long id; + private String name; + + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/jpa/ql/MapIssueTest.java b/hibernate-core/src/test/java/org/hibernate/test/jpa/ql/MapIssueTest.java new file mode 100644 index 0000000000..6f18811863 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/jpa/ql/MapIssueTest.java @@ -0,0 +1,44 @@ +/* + * 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.jpa.ql; + +import org.hibernate.Session; +import org.hibernate.test.jpa.AbstractJPATest; +import org.hibernate.test.jpa.MapContent; +import org.hibernate.test.jpa.MapOwner; +import org.hibernate.test.jpa.Relationship; +import org.junit.Test; + +public class MapIssueTest extends AbstractJPATest { + + @Override + public String[] getMappings() { + return new String[] {}; + } + + protected Class[] getAnnotatedClasses() { + return new Class[] { MapOwner.class, MapContent.class, Relationship.class}; + } + + @Test + public void testWhereSubqueryMapKeyIsEntityWhereWithKey() { + Session s = openSession(); + s.beginTransaction(); + s.createQuery( "select r from Relationship r where exists (select 1 from MapOwner as o left join o.contents c with key(c) = r)" ).list(); + s.getTransaction().commit(); + s.close(); + } + + @Test + public void testMapKeyIsEntityWhereWithKey() { + Session s = openSession(); + s.beginTransaction(); + s.createQuery( "select 1 from MapOwner as o left join o.contents c where c.id is not null" ).list(); + s.getTransaction().commit(); + s.close(); + } +}