-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
hibernate-core/src/test/java/org/hibernate/orm/test/annotations/basic/SetAsBasicTest.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,87 @@ | ||
/* | ||
* 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 <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.orm.test.annotations.basic; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.hibernate.testing.orm.junit.DomainModel; | ||
import org.hibernate.testing.orm.junit.SessionFactory; | ||
import org.hibernate.testing.orm.junit.SessionFactoryScope; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
@DomainModel( | ||
annotatedClasses = { | ||
SetAsBasicTest.Post.class | ||
} | ||
) | ||
@SessionFactory | ||
public class SetAsBasicTest { | ||
|
||
@Test | ||
public void testPersist(SessionFactoryScope scope) { | ||
Integer postId = 1; | ||
scope.inTransaction( | ||
session -> { | ||
Set<String> tags = new HashSet<>(); | ||
tags.add( "tag1" ); | ||
|
||
Post post = new Post( postId, "post", tags ); | ||
session.persist( post ); | ||
} | ||
); | ||
|
||
scope.inTransaction( | ||
session -> { | ||
Post post = session.find( Post.class, postId ); | ||
Set<String> tags = post.getTags(); | ||
assertThat( tags ).isNotNull(); | ||
assertThat( tags.size() ).isEqualTo( 1 ); | ||
assertThat( tags.stream().findFirst().get() ).isEqualTo( "tag1" ); | ||
} | ||
); | ||
} | ||
|
||
@Entity | ||
@Table(name = "post") | ||
public static class Post { | ||
@Id | ||
public Integer id; | ||
|
||
public String name; | ||
|
||
Set<String> tags; | ||
|
||
public Post() { | ||
} | ||
|
||
public Post(Integer id, String name, Set<String> tags) { | ||
this.id = id; | ||
this.name = name; | ||
this.tags = tags; | ||
} | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public Set<String> getTags() { | ||
return tags; | ||
} | ||
} | ||
|
||
} |
83 changes: 83 additions & 0 deletions
83
...e-core/src/test/java/org/hibernate/orm/test/annotations/basic/TreeMapAsBasicTypeTest.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,83 @@ | ||
package org.hibernate.orm.test.annotations.basic; | ||
|
||
import java.util.TreeMap; | ||
|
||
import org.hibernate.testing.orm.junit.DomainModel; | ||
import org.hibernate.testing.orm.junit.JiraKey; | ||
import org.hibernate.testing.orm.junit.SessionFactory; | ||
import org.hibernate.testing.orm.junit.SessionFactoryScope; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
@JiraKey("HHH-17320") | ||
@DomainModel( | ||
annotatedClasses = { | ||
TreeMapAsBasicTypeTest.Customer.class | ||
} | ||
) | ||
@SessionFactory | ||
public class TreeMapAsBasicTypeTest { | ||
|
||
@Test | ||
public void testPersist(SessionFactoryScope scope) { | ||
Long cutomerId = 1l; | ||
scope.inTransaction( | ||
session -> { | ||
TreeMap<String, Integer> data = new TreeMap<>(); | ||
data.put( "key", 1 ); | ||
TreeMap<String, String> data2 = new TreeMap<>(); | ||
data2.put( "key2", "2" ); | ||
Customer c = new Customer( cutomerId, data, data2 ); | ||
session.persist( c ); | ||
} | ||
); | ||
|
||
scope.inTransaction( | ||
session -> { | ||
Customer customer = session.find( Customer.class, cutomerId ); | ||
TreeMap<String, Integer> data = customer.getData(); | ||
assertThat( data ).isNotNull(); | ||
assertThat( data.get( "key" ) ).isEqualTo( 1 ); | ||
TreeMap<String, String> data2 = customer.getData2(); | ||
assertThat( data2 ).isNotNull(); | ||
assertThat( data2.get( "key2" ) ).isEqualTo( "2" ); | ||
} | ||
); | ||
} | ||
|
||
@Entity(name = "Customer") | ||
public static class Customer { | ||
|
||
@Id | ||
private Long id; | ||
|
||
private TreeMap<String, Integer> data; | ||
|
||
private TreeMap<String, String> data2; | ||
|
||
public Customer() { | ||
} | ||
|
||
public Customer(Long id, TreeMap<String, Integer> data, TreeMap<String, String> data2) { | ||
this.id = id; | ||
this.data = data; | ||
this.data2 = data2; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public TreeMap<String, Integer> getData() { | ||
return data; | ||
} | ||
|
||
public TreeMap<String, String> getData2() { | ||
return data2; | ||
} | ||
} | ||
} |