-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
774ab0f
commit 88e70fa
Showing
3 changed files
with
125 additions
and
4 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
85 changes: 85 additions & 0 deletions
85
modules/spring-data/src/test/java/org/stubit/springdata/EmbeddedIdTestEntity.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,85 @@ | ||
package org.stubit.springdata; | ||
|
||
import static java.util.UUID.randomUUID; | ||
|
||
import jakarta.persistence.Embeddable; | ||
import jakarta.persistence.EmbeddedId; | ||
import java.util.Objects; | ||
import java.util.UUID; | ||
import org.stubit.random.RandomString; | ||
|
||
class EmbeddedIdTestEntity { | ||
|
||
@EmbeddedId private Id id; | ||
private String name; | ||
|
||
public EmbeddedIdTestEntity(Id id, String name) { | ||
this.id = id; | ||
this.name = name; | ||
} | ||
|
||
public static EmbeddedIdTestEntity randomEntity() { | ||
return new EmbeddedIdTestEntity(new Id(randomUUID()), RandomString.latinLetters(8)); | ||
} | ||
|
||
public Id getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Id id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
EmbeddedIdTestEntity entity = (EmbeddedIdTestEntity) o; | ||
return Objects.equals(id, entity.id) && Objects.equals(name, entity.name); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, name); | ||
} | ||
|
||
@Embeddable | ||
static class Id { | ||
private UUID uuid; | ||
|
||
public Id() {} | ||
|
||
public Id(UUID uuid) { | ||
this.uuid = uuid; | ||
} | ||
|
||
public UUID getId() { | ||
return uuid; | ||
} | ||
|
||
public void setId(UUID uuid) { | ||
this.uuid = uuid; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Id entity = (Id) o; | ||
return Objects.equals(uuid, entity.uuid); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(uuid); | ||
} | ||
} | ||
} |