Author: brmeyer
Date: 2013-05-03 13:45:32 -0400 (Fri, 03 May 2013)
New Revision: 21109
Added:
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/querycache/
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/querycache/CompositeKey.java
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/querycache/EntityWithCompositeKey.java
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/querycache/EntityWithStringCompositeKey.java
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/querycache/QueryCacheTest.java
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/querycache/StringCompositeKey.java
Log:
HHH-4457 Query with Composite Primary Key parameter crashes when query cache is on
Added:
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/querycache/CompositeKey.java
===================================================================
---
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/querycache/CompositeKey.java
(rev 0)
+++
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/querycache/CompositeKey.java 2013-05-03
17:45:32 UTC (rev 21109)
@@ -0,0 +1,49 @@
+package org.hibernate.test.annotations.querycache;
+
+import java.io.Serializable;
+
+import javax.persistence.Embeddable;
+
+@Embeddable
+public class CompositeKey implements Serializable {
+
+ private static final long serialVersionUID = 7950910288405475131L;
+
+ public int a;
+
+ public int b;
+
+ public CompositeKey() {
+ }
+
+ public CompositeKey(int a, int b) {
+ this.a = a;
+ this.b = b;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + a;
+ result = prime * result + b;
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ CompositeKey other = (CompositeKey) obj;
+ if (a != other.a)
+ return false;
+ if (b != other.b)
+ return false;
+ return true;
+ }
+
+}
\ No newline at end of file
Property changes on:
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/querycache/CompositeKey.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/querycache/EntityWithCompositeKey.java
===================================================================
---
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/querycache/EntityWithCompositeKey.java
(rev 0)
+++
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/querycache/EntityWithCompositeKey.java 2013-05-03
17:45:32 UTC (rev 21109)
@@ -0,0 +1,19 @@
+package org.hibernate.test.annotations.querycache;
+
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+
+@Entity
+public class EntityWithCompositeKey {
+
+ @EmbeddedId
+ public CompositeKey pk;
+
+ public EntityWithCompositeKey() {
+ }
+
+ public EntityWithCompositeKey(CompositeKey pk) {
+ this.pk = pk;
+ }
+
+}
\ No newline at end of file
Property changes on:
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/querycache/EntityWithCompositeKey.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/querycache/EntityWithStringCompositeKey.java
===================================================================
---
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/querycache/EntityWithStringCompositeKey.java
(rev 0)
+++
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/querycache/EntityWithStringCompositeKey.java 2013-05-03
17:45:32 UTC (rev 21109)
@@ -0,0 +1,23 @@
+package org.hibernate.test.annotations.querycache;
+
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+
+import org.hibernate.annotations.Cache;
+import org.hibernate.annotations.CacheConcurrencyStrategy;
+
+@Entity
+@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
+public class EntityWithStringCompositeKey {
+
+ private StringCompositeKey pk;
+
+ @EmbeddedId
+ public StringCompositeKey getPk() {
+ return pk;
+ }
+
+ public void setPk(StringCompositeKey pk) {
+ this.pk = pk;
+ }
+}
Property changes on:
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/querycache/EntityWithStringCompositeKey.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/querycache/QueryCacheTest.java
===================================================================
---
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/querycache/QueryCacheTest.java
(rev 0)
+++
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/querycache/QueryCacheTest.java 2013-05-03
17:45:32 UTC (rev 21109)
@@ -0,0 +1,69 @@
+package org.hibernate.test.annotations.querycache;
+
+import org.hibernate.Criteria;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.criterion.Restrictions;
+import org.hibernate.test.annotations.TestCase;
+
+public class QueryCacheTest extends TestCase {
+
+ private static final CompositeKey PK = new CompositeKey(1, 2);
+
+ @Override
+ protected Class[] getAnnotatedClasses() {
+ return new Class[] {
+ CompositeKey.class,
+ EntityWithCompositeKey.class,
+ StringCompositeKey.class,
+ EntityWithStringCompositeKey.class
+ };
+ }
+
+ @Override
+ public void configure(Configuration cfg) {
+ super.configure( cfg );
+ cfg.setProperty( Environment.USE_QUERY_CACHE, "true" );
+ cfg.setProperty( Environment.CACHE_REGION_PREFIX, "foo" );
+ cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "true" );
+ cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
+ }
+
+// @Override
+// protected String getCacheConcurrencyStrategy() {
+// return "nonstrict-read-write";
+// }
+
+// @TestForIssue( jiraKey = "HHH-4459" )
+ public void testGetByCompositeId() {
+ Session s = openSession();
+ s.beginTransaction();
+ s.persist( new EntityWithCompositeKey( PK ) );
+ Query query = s.createQuery( "FROM EntityWithCompositeKey e WHERE e.pk = :pk"
);
+ query.setCacheable( true );
+ query.setParameter( "pk", PK );
+ assertEquals(1, query.list().size( ));
+ s.getTransaction().rollback();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ EntityWithStringCompositeKey entity = new EntityWithStringCompositeKey();
+ StringCompositeKey key = new StringCompositeKey();
+ key.setAnalog( "foo1" );
+ key.setDevice( "foo2" );
+ key.setDeviceType( "foo3" );
+ key.setSubstation( "foo4" );
+ entity.setPk( key );
+ s.persist( entity );
+ Criteria c = s.createCriteria(
+ EntityWithStringCompositeKey.class ).add( Restrictions.eq(
+ "pk", key ) );
+ c.setCacheable( true );
+ assertEquals( 1, c.list().size() );
+ s.getTransaction().rollback();
+ s.close();
+ }
+}
Property changes on:
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/querycache/QueryCacheTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/querycache/StringCompositeKey.java
===================================================================
---
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/querycache/StringCompositeKey.java
(rev 0)
+++
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/querycache/StringCompositeKey.java 2013-05-03
17:45:32 UTC (rev 21109)
@@ -0,0 +1,51 @@
+package org.hibernate.test.annotations.querycache;
+
+import java.io.Serializable;
+
+import javax.persistence.Embeddable;
+
+@Embeddable
+public class StringCompositeKey implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private String substation;
+
+ private String deviceType;
+
+ private String device;
+
+ public String getSubstation() {
+ return substation;
+ }
+
+ public void setSubstation(String substation) {
+ this.substation = substation;
+ }
+
+ public String getDeviceType() {
+ return deviceType;
+ }
+
+ public void setDeviceType(String deviceType) {
+ this.deviceType = deviceType;
+ }
+
+ public String getDevice() {
+ return device;
+ }
+
+ public void setDevice(String device) {
+ this.device = device;
+ }
+
+ public String getAnalog() {
+ return analog;
+ }
+
+ public void setAnalog(String analog) {
+ this.analog = analog;
+ }
+
+ private String analog;
+}
Property changes on:
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/querycache/StringCompositeKey.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Show replies by date