mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1952 - Entity bean with @Id and ONLY @WhenCreated treated as reference bean - not inserted
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package org.tests.model.embedded;
|
||||
|
||||
import io.ebean.DB;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TestEmbeddedEqualsWhenCreated {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
UserInterestLive bean = new UserInterestLive(new UserInterestLiveKey(1L, 2L));
|
||||
bean.save();
|
||||
|
||||
final UserInterestLive found = DB.find(UserInterestLive.class, bean.getKey());
|
||||
assertEquals(found, bean); // <- failed as bean not inserted
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.tests.model.embedded;
|
||||
|
||||
import io.ebean.Model;
|
||||
import io.ebean.annotation.CreatedTimestamp;
|
||||
|
||||
import javax.persistence.EmbeddedId;
|
||||
import javax.persistence.Entity;
|
||||
import java.util.Date;
|
||||
|
||||
@Entity
|
||||
public class UserInterestLive extends Model {
|
||||
|
||||
@EmbeddedId
|
||||
private final UserInterestLiveKey key;
|
||||
|
||||
@CreatedTimestamp
|
||||
private Date createdAt;
|
||||
|
||||
public UserInterestLive(UserInterestLiveKey key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public UserInterestLiveKey getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public Date getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(Date createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package org.tests.model.embedded;
|
||||
|
||||
import javax.persistence.Embeddable;
|
||||
import java.util.Objects;
|
||||
|
||||
@Embeddable
|
||||
public class UserInterestLiveKey {
|
||||
|
||||
private long userId;
|
||||
private long liveId;
|
||||
|
||||
public UserInterestLiveKey(long userId, long liveId) {
|
||||
this.userId = userId;
|
||||
this.liveId = liveId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
UserInterestLiveKey that = (UserInterestLiveKey) o;
|
||||
return userId == that.userId &&
|
||||
liveId == that.liveId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(userId, liveId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user