-
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.
False positive "class should override both the equals and hashCode me…
…thods" for Enum values #295
- Loading branch information
1 parent
c0defb2
commit abe66ce
Showing
8 changed files
with
181 additions
and
9 deletions.
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
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
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
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
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
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
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
95 changes: 95 additions & 0 deletions
95
...pes-52/src/test/java/com/vladmihalcea/hibernate/type/json/PostgreSQLJsonListEnumTest.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,95 @@ | ||
package com.vladmihalcea.hibernate.type.json; | ||
|
||
import com.vladmihalcea.hibernate.type.util.AbstractPostgreSQLIntegrationTest; | ||
import org.hibernate.Session; | ||
import org.hibernate.annotations.NaturalId; | ||
import org.hibernate.annotations.Type; | ||
import org.hibernate.annotations.TypeDef; | ||
import org.junit.Test; | ||
|
||
import javax.persistence.*; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* @author Vlad Mihalcea | ||
*/ | ||
public class PostgreSQLJsonListEnumTest extends AbstractPostgreSQLIntegrationTest { | ||
|
||
@Override | ||
protected Class<?>[] entities() { | ||
return new Class<?>[]{ | ||
Book.class | ||
}; | ||
} | ||
|
||
@Test | ||
public void test() { | ||
|
||
doInJPA(entityManager -> { | ||
entityManager.persist( | ||
new Book() | ||
.setIsbn("978-9730228236") | ||
.addProperty(PropertyType.BEST_SELLER) | ||
.addProperty(PropertyType.FREE_CHAPTER) | ||
); | ||
}); | ||
|
||
doInJPA(entityManager -> { | ||
Book book = entityManager.unwrap(Session.class) | ||
.bySimpleNaturalId(Book.class) | ||
.load("978-9730228236"); | ||
|
||
List<PropertyType> bookProperties = book.getProperties(); | ||
assertEquals(2, bookProperties.size()); | ||
}); | ||
} | ||
|
||
@Entity(name = "Book") | ||
@Table(name = "book") | ||
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class) | ||
public static class Book { | ||
|
||
@Id | ||
@GeneratedValue | ||
private Long id; | ||
|
||
@NaturalId | ||
@Column(length = 15) | ||
private String isbn; | ||
|
||
@Type(type = "jsonb") | ||
@Column(columnDefinition = "jsonb") | ||
private List<PropertyType> propertyTypes = new ArrayList<>(); | ||
|
||
public String getIsbn() { | ||
return isbn; | ||
} | ||
|
||
public Book setIsbn(String isbn) { | ||
this.isbn = isbn; | ||
return this; | ||
} | ||
|
||
public List<PropertyType> getProperties() { | ||
return propertyTypes; | ||
} | ||
|
||
public Book setProperties(List<PropertyType> properties) { | ||
this.propertyTypes = properties; | ||
return this; | ||
} | ||
|
||
public Book addProperty(PropertyType propertyType) { | ||
propertyTypes.add(propertyType); | ||
return this; | ||
} | ||
} | ||
|
||
public enum PropertyType { | ||
BEST_SELLER, | ||
FREE_CHAPTER | ||
} | ||
} |