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:
@@ -11,6 +11,8 @@ import org.tests.model.basic.Order;
|
||||
import org.tests.model.composite.RCustomer;
|
||||
import org.tests.model.composite.RCustomerKey;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.embedded.UserInterestLive;
|
||||
import org.tests.model.embedded.UserInterestLiveKey;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Map;
|
||||
@@ -56,13 +58,21 @@ public class TestBeanDescriptorHasIdProperty extends BaseTestCase {
|
||||
|
||||
Customer order = new Customer();
|
||||
EntityBeanIntercept ebi = getIntercept(order);
|
||||
assertFalse(beanDescriptor.hasIdPropertyOnly(ebi));
|
||||
assertFalse(beanDescriptor.referenceIdPropertyOnly(ebi));
|
||||
|
||||
order.setId(23);
|
||||
assertTrue(beanDescriptor.hasIdPropertyOnly(ebi));
|
||||
assertTrue(beanDescriptor.referenceIdPropertyOnly(ebi));
|
||||
|
||||
order.setName("custName");
|
||||
assertFalse(beanDescriptor.hasIdPropertyOnly(ebi));
|
||||
assertFalse(beanDescriptor.referenceIdPropertyOnly(ebi));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isReference_withGeneratedOnInsertOnlyProperty_expect_false() {
|
||||
BeanDescriptor<UserInterestLive> descriptor = spiServer.getBeanDescriptor(UserInterestLive.class);
|
||||
UserInterestLive bean = new UserInterestLive(new UserInterestLiveKey(1L, 2L));
|
||||
EntityBeanIntercept ebi = getIntercept(bean);
|
||||
assertFalse(descriptor.referenceIdPropertyOnly(ebi));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package io.ebeaninternal.server.deploy.generatedproperty;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class GeneratedInsertJavaTimeTest {
|
||||
|
||||
@Test
|
||||
public void test_generatedOnInsert() {
|
||||
|
||||
GeneratedProperty gen = new GeneratedInsertJavaTime.InstantDT();
|
||||
assertTrue(GeneratedWhenCreated.class.isInstance(gen));
|
||||
assertTrue(gen instanceof GeneratedWhenCreated);
|
||||
}
|
||||
}
|
||||
@@ -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