-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return original object if target and original are the same when merging
- Loading branch information
1 parent
4968e53
commit 64f5f47
Showing
6 changed files
with
154 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...src/test/java/io/hypersistence/utils/hibernate/type/json/PostgreSQLJsonTypeMergeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.hypersistence.utils.hibernate.type.json; | ||
|
||
import io.hypersistence.utils.hibernate.type.model.Event; | ||
import io.hypersistence.utils.hibernate.type.model.Location; | ||
import io.hypersistence.utils.hibernate.type.model.Participant; | ||
import io.hypersistence.utils.hibernate.util.AbstractPostgreSQLIntegrationTest; | ||
import org.junit.Test; | ||
|
||
import static java.lang.System.identityHashCode; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* @author Simone Giusso | ||
*/ | ||
public class PostgreSQLJsonTypeMergeTest extends AbstractPostgreSQLIntegrationTest { | ||
|
||
@Override | ||
protected Class<?>[] entities() { | ||
return new Class<?>[]{ | ||
Event.class, | ||
Participant.class | ||
}; | ||
} | ||
|
||
@Test | ||
public void test() { | ||
doInJPA(entityManager -> { | ||
Location location = new Location(); | ||
location.setCountry("Romania"); | ||
location.setCity("Cluj-Napoca"); | ||
|
||
Event event = new Event(); | ||
event.setId(1L); | ||
event.setLocation(location); | ||
entityManager.persist(event); | ||
|
||
event = entityManager.merge(event); | ||
|
||
assertThatMergeReturnsTheOriginalJsonTypeObject(event.getLocation(), location); | ||
}); | ||
} | ||
|
||
private void assertThatMergeReturnsTheOriginalJsonTypeObject(Location target, Location original) { | ||
assertEquals(identityHashCode(original), identityHashCode(target)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...src/test/java/io/hypersistence/utils/hibernate/type/json/PostgreSQLJsonTypeMergeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.hypersistence.utils.hibernate.type.json; | ||
|
||
import io.hypersistence.utils.hibernate.type.model.Event; | ||
import io.hypersistence.utils.hibernate.type.model.Location; | ||
import io.hypersistence.utils.hibernate.type.model.Participant; | ||
import io.hypersistence.utils.hibernate.util.AbstractPostgreSQLIntegrationTest; | ||
import org.junit.Test; | ||
|
||
import static java.lang.System.identityHashCode; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* @author Simone Giusso | ||
*/ | ||
public class PostgreSQLJsonTypeMergeTest extends AbstractPostgreSQLIntegrationTest { | ||
|
||
@Override | ||
protected Class<?>[] entities() { | ||
return new Class<?>[]{ | ||
Event.class, | ||
Participant.class | ||
}; | ||
} | ||
|
||
@Test | ||
public void test() { | ||
doInJPA(entityManager -> { | ||
Location location = new Location(); | ||
location.setCountry("Romania"); | ||
location.setCity("Cluj-Napoca"); | ||
|
||
Event event = new Event(); | ||
event.setId(1L); | ||
event.setLocation(location); | ||
entityManager.persist(event); | ||
|
||
event = entityManager.merge(event); | ||
|
||
assertThatMergeReturnsTheOriginalJsonTypeObject(event.getLocation(), location); | ||
}); | ||
} | ||
|
||
private void assertThatMergeReturnsTheOriginalJsonTypeObject(Location target, Location original) { | ||
assertEquals(identityHashCode(original), identityHashCode(target)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...src/test/java/io/hypersistence/utils/hibernate/type/json/PostgreSQLJsonTypeMergeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.hypersistence.utils.hibernate.type.json; | ||
|
||
import io.hypersistence.utils.hibernate.type.model.Event; | ||
import io.hypersistence.utils.hibernate.type.model.Location; | ||
import io.hypersistence.utils.hibernate.type.model.Participant; | ||
import io.hypersistence.utils.hibernate.util.AbstractPostgreSQLIntegrationTest; | ||
import org.junit.Test; | ||
|
||
import static java.lang.System.identityHashCode; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* @author Simone Giusso | ||
*/ | ||
public class PostgreSQLJsonTypeMergeTest extends AbstractPostgreSQLIntegrationTest { | ||
|
||
@Override | ||
protected Class<?>[] entities() { | ||
return new Class<?>[]{ | ||
Event.class, | ||
Participant.class | ||
}; | ||
} | ||
|
||
@Test | ||
public void test() { | ||
doInJPA(entityManager -> { | ||
Location location = new Location(); | ||
location.setCountry("Romania"); | ||
location.setCity("Cluj-Napoca"); | ||
|
||
Event event = new Event(); | ||
event.setId(1L); | ||
event.setLocation(location); | ||
entityManager.persist(event); | ||
|
||
event = entityManager.merge(event); | ||
|
||
assertThatMergeReturnsTheOriginalJsonTypeObject(event.getLocation(), location); | ||
}); | ||
} | ||
|
||
private void assertThatMergeReturnsTheOriginalJsonTypeObject(Location target, Location original) { | ||
assertEquals(identityHashCode(original), identityHashCode(target)); | ||
} | ||
|
||
} |