-
Notifications
You must be signed in to change notification settings - Fork 54.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from andrebrowne/BAEL-4077
BAEL-4007 Add jpa data equality unit test specs
- Loading branch information
Showing
8 changed files
with
402 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## JPA in Java | ||
|
||
This module contains articles about the Java Persistence API (JPA) in 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,139 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>java-jpa-3</artifactId> | ||
<name>java-jpa-3</name> | ||
|
||
<parent> | ||
<groupId>com.baeldung</groupId> | ||
<artifactId>persistence-modules</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.hibernate</groupId> | ||
<artifactId>hibernate-core</artifactId> | ||
<version>${hibernate.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hibernate</groupId> | ||
<artifactId>hibernate-jpamodelgen</artifactId> | ||
<version>${hibernate.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
<version>${h2.version}</version> | ||
</dependency> | ||
|
||
<!--Compile time JPA API --> | ||
<dependency> | ||
<groupId>javax.persistence</groupId> | ||
<artifactId>javax.persistence-api</artifactId> | ||
<version>${javax.persistence-api.version}</version> | ||
</dependency> | ||
|
||
<!--Runtime JPA implementation --> | ||
<dependency> | ||
<groupId>org.eclipse.persistence</groupId> | ||
<artifactId>eclipselink</artifactId> | ||
<version>${eclipselink.version}</version> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.postgresql</groupId> | ||
<artifactId>postgresql</artifactId> | ||
<version>${postgres.version}</version> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<version>${assertj.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>${maven-compiler-plugin.version}</version> | ||
<configuration> | ||
<compilerArgument>-proc:none</compilerArgument> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.bsc.maven</groupId> | ||
<artifactId>maven-processor-plugin</artifactId> | ||
<version>${maven-processor-plugin.version}</version> | ||
<executions> | ||
<execution> | ||
<id>process</id> | ||
<goals> | ||
<goal>process</goal> | ||
</goals> | ||
<phase>generate-sources</phase> | ||
<configuration> | ||
<outputDirectory>target/metamodel</outputDirectory> | ||
<processors> | ||
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor> | ||
</processors> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>build-helper-maven-plugin</artifactId> | ||
<version>${build-helper-maven-plugin.version}</version> | ||
<executions> | ||
<execution> | ||
<id>add-source</id> | ||
<phase>generate-sources</phase> | ||
<goals> | ||
<goal>add-source</goal> | ||
</goals> | ||
<configuration> | ||
<sources> | ||
<source>target/metamodel</source> | ||
<source>${project.build.directory}/generated-sources/java/</source> | ||
</sources> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.mysema.maven</groupId> | ||
<artifactId>apt-maven-plugin</artifactId> | ||
<version>1.1.3</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>process</goal> | ||
</goals> | ||
<configuration> | ||
<outputDirectory>target/generated-sources/java</outputDirectory> | ||
<processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<properties> | ||
<hibernate.version>5.4.14.Final</hibernate.version> | ||
<eclipselink.version>2.7.4</eclipselink.version> | ||
<postgres.version>42.2.5</postgres.version> | ||
<javax.persistence-api.version>2.2</javax.persistence-api.version> | ||
<assertj.version>3.11.1</assertj.version> | ||
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version> | ||
<maven-processor-plugin.version>3.3.3</maven-processor-plugin.version> | ||
<build-helper-maven-plugin.version>3.0.0</build-helper-maven-plugin.version> | ||
</properties> | ||
|
||
</project> |
54 changes: 54 additions & 0 deletions
54
...stence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByBusinessKey.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,54 @@ | ||
package com.baeldung.jpa.equality; | ||
|
||
import javax.persistence.*; | ||
|
||
@Entity | ||
public class EqualByBusinessKey { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private Long id; | ||
|
||
private String email; | ||
|
||
public EqualByBusinessKey() { | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getEmail() { | ||
return email; | ||
} | ||
|
||
public void setEmail(String email) { | ||
this.email = email; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
final int prime = 31; | ||
int result = 1; | ||
result = prime * result + ((email == null) ? 0 : email.hashCode()); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (obj instanceof EqualByBusinessKey) | ||
if (((EqualByBusinessKey) obj).getEmail() == getEmail()) | ||
return true; | ||
|
||
return false; | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualById.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,54 @@ | ||
package com.baeldung.jpa.equality; | ||
|
||
import javax.persistence.*; | ||
|
||
@Entity | ||
public class EqualById { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private Long id; | ||
|
||
private String email; | ||
|
||
public EqualById() { | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getEmail() { | ||
return email; | ||
} | ||
|
||
public void setEmail(String email) { | ||
this.email = email; | ||
} | ||
|
||
|
||
@Override | ||
public int hashCode() { | ||
final int prime = 31; | ||
int result = 1; | ||
result = prime * result + ((id == null) ? 0 : id.hashCode()); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (obj instanceof EqualById) | ||
return ((EqualById) obj).getId() == getId(); | ||
|
||
return false; | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
...stence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByJavaDefault.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,38 @@ | ||
package com.baeldung.jpa.equality; | ||
|
||
import javax.persistence.*; | ||
|
||
@Entity | ||
public class EqualByJavaDefault implements Cloneable{ | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private Long id; | ||
|
||
private String email; | ||
|
||
public EqualByJavaDefault() { | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getEmail() { | ||
return email; | ||
} | ||
|
||
public void setEmail(String email) { | ||
this.email = email; | ||
} | ||
|
||
public Object clone() throws | ||
CloneNotSupportedException | ||
{ | ||
return super.clone(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml
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,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence | ||
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd" | ||
version="2.2"> | ||
<persistence-unit name="jpa-h2-equality"> | ||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> | ||
<class>com.baeldung.jpa.equality.EqualByJavaDefault</class> | ||
<class>com.baeldung.jpa.equality.EqualById</class> | ||
<class>com.baeldung.jpa.equality.EqualByBusinessKey</class> | ||
<exclude-unlisted-classes>true</exclude-unlisted-classes> | ||
<properties> | ||
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver" /> | ||
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test" /> | ||
<property name="javax.persistence.jdbc.user" value="sa" /> | ||
<property name="javax.persistence.jdbc.password" value="" /> | ||
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver" /> | ||
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" /> | ||
<property name="hibernate.hbm2ddl.auto" value="create-drop" /> | ||
<property name="show_sql" value="false" /> | ||
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false" /> | ||
</properties> | ||
</persistence-unit> | ||
</persistence> |
15 changes: 15 additions & 0 deletions
15
persistence-modules/java-jpa-3/src/main/resources/logback.xml
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,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
<appender name="STDOUT" | ||
class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - | ||
%msg%n | ||
</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="INFO"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
</configuration> |
Oops, something went wrong.