Skip to content

Commit

Permalink
HHH-10111 - AttributeConverter based attributes are not marked for up…
Browse files Browse the repository at this point in the history
…date when their state is modified
  • Loading branch information
sebersole committed Sep 24, 2015
1 parent bb0b604 commit 70c9c8e
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 36 deletions.
Expand Up @@ -13,7 +13,6 @@
import java.util.List;
import java.util.Map;
import javax.persistence.AttributeConverter;
import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
Expand All @@ -29,12 +28,12 @@
import org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter;

import org.hibernate.testing.TestForIssue;

import org.junit.Test;

import org.joda.time.LocalDate;

import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* @author Steve Ebersole
Expand Down Expand Up @@ -89,22 +88,25 @@ public List<String> getManagedClassNames() {
final AttributeConverterTypeAdapter type = assertTyping( AttributeConverterTypeAdapter.class, theDatePropertyType );
assertTyping( JodaLocalDateConverter.class, type.getAttributeConverter() );

int previousCallCount = 0;

try {
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.persist( new TheEntity( 1, new LocalDate() ) );
em.getTransaction().commit();
em.close();

assertEquals( 1, callsToConverter );
assertTrue( previousCallCount < callsToConverter );
previousCallCount = callsToConverter;

em = emf.createEntityManager();
em.getTransaction().begin();
em.find( TheEntity.class, 1 );
em.getTransaction().commit();
em.close();

assertEquals( 2, callsToConverter );
assertTrue( previousCallCount < callsToConverter );

em = emf.createEntityManager();
em.getTransaction().begin();
Expand Down
Expand Up @@ -31,7 +31,7 @@
import org.junit.Test;

import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* @author Steve Ebersole
Expand Down Expand Up @@ -93,22 +93,25 @@ public List<String> getManagedClassNames() {
final AttributeConverterTypeAdapter type = assertTyping( AttributeConverterTypeAdapter.class, theDatePropertyType );
assertTyping( LongToDateConverter.class, type.getAttributeConverter() );

int previousCallCount = 0;

try {
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.persist( new Entity1( 1, "1", new Date() ) );
em.getTransaction().commit();
em.close();

assertEquals( 1, callsToConverter );
assertTrue( previousCallCount < callsToConverter );
previousCallCount = callsToConverter;

em = emf.createEntityManager();
em.getTransaction().begin();
em.find( Entity1.class, 1 );
em.getTransaction().commit();
em.close();

assertEquals( 2, callsToConverter );
assertTrue( previousCallCount < callsToConverter );

em = emf.createEntityManager();
em.getTransaction().begin();
Expand Down
Expand Up @@ -8,7 +8,6 @@

import java.net.MalformedURLException;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -31,7 +30,7 @@
import org.junit.Test;

import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* @author Steve Ebersole
Expand Down Expand Up @@ -101,22 +100,25 @@ public List<String> getManagedClassNames() {
final AttributeConverterTypeAdapter type = assertTyping( AttributeConverterTypeAdapter.class, theDatePropertyType );
assertTyping( MediaTypeConverter.class, type.getAttributeConverter() );

int previousCallCount = 0;

try {
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.persist( new Entity1( 1, "300", MediaType.VIDEO ) );
em.getTransaction().commit();
em.close();

assertEquals( 1, callsToConverter );
assertTrue( previousCallCount < callsToConverter );
previousCallCount = callsToConverter;

em = emf.createEntityManager();
em.getTransaction().begin();
em.find( Entity1.class, 1 );
em.getTransaction().commit();
em.close();

assertEquals( 2, callsToConverter );
assertTrue( previousCallCount < callsToConverter );

em = emf.createEntityManager();
em.getTransaction().begin();
Expand Down
Expand Up @@ -6,6 +6,12 @@
*/
package org.hibernate.jpa.test.convert;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.AttributeConverter;
import javax.persistence.Convert;
import javax.persistence.Converter;
Expand All @@ -14,13 +20,6 @@
import javax.persistence.EntityManagerFactory;
import javax.persistence.Id;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.jpa.boot.spi.Bootstrap;
Expand All @@ -29,12 +28,11 @@
import org.hibernate.type.Type;
import org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter;

import org.junit.Test;

import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test;

import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* @author Steve Ebersole
Expand Down Expand Up @@ -68,7 +66,7 @@ public List<String> getManagedClassNames() {
em.getTransaction().commit();
em.close();

assertEquals( 1, callsToConverter );
assertTrue( 0 < callsToConverter );

em = emf.createEntityManager();
em.getTransaction().begin();
Expand Down
Expand Up @@ -6,6 +6,12 @@
*/
package org.hibernate.jpa.test.convert;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.AttributeConverter;
import javax.persistence.Convert;
import javax.persistence.Converter;
Expand All @@ -14,12 +20,6 @@
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Id;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.spi.SessionFactoryImplementor;
Expand All @@ -29,12 +29,11 @@
import org.hibernate.type.Type;
import org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter;

import org.junit.Test;

import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test;

import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* @author Steve Ebersole
Expand Down Expand Up @@ -68,7 +67,7 @@ public List<String> getManagedClassNames() {
em.getTransaction().commit();
em.close();

assertEquals( 1, callsToConverter );
assertTrue( 0 < callsToConverter );

em = emf.createEntityManager();
em.getTransaction().begin();
Expand Down
Expand Up @@ -33,7 +33,7 @@
import org.junit.Test;

import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* Jira HHH-8812 claims that explicit {@link javax.persistence.Convert} annotations are not processed when a orm.xml
Expand Down Expand Up @@ -111,22 +111,25 @@ public List<String> getMappingFileNames() {
final AttributeConverterTypeAdapter type = assertTyping( AttributeConverterTypeAdapter.class, theDatePropertyType );
assertTyping( LongToDateConverter.class, type.getAttributeConverter() );

int previousCallCount = 0;

try {
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.persist( new Entity1( 1, "1", new Date() ) );
em.getTransaction().commit();
em.close();

assertEquals( 1, callsToConverter );
assertTrue( previousCallCount < callsToConverter );
previousCallCount = callsToConverter;

em = emf.createEntityManager();
em.getTransaction().begin();
em.find( Entity1.class, 1 );
em.getTransaction().commit();
em.close();

assertEquals( 2, callsToConverter );
assertTrue( previousCallCount < callsToConverter );

em = emf.createEntityManager();
em.getTransaction().begin();
Expand Down

0 comments on commit 70c9c8e

Please sign in to comment.