mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1990 - NPE with @Cache and setting naturalKey to null
This commit is contained in:
@@ -10,7 +10,7 @@ import javax.persistence.UniqueConstraint;
|
||||
@UniqueConstraint(columnNames = "app_name")
|
||||
public class OCachedApp extends OCacheBase {
|
||||
|
||||
private final String appName;
|
||||
private String appName;
|
||||
|
||||
public OCachedApp(String appName) {
|
||||
this.appName = appName;
|
||||
@@ -19,4 +19,8 @@ public class OCachedApp extends OCacheBase {
|
||||
public String getAppName() {
|
||||
return appName;
|
||||
}
|
||||
|
||||
public void setAppName(String appName) {
|
||||
this.appName = appName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package org.tests.model.basic.cache;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestNatKeyCacheWhenNull extends BaseTestCase {
|
||||
|
||||
public static final String WILL_CHANGE_TO_NULL = "WillChangeToNull";
|
||||
|
||||
@Test
|
||||
public void updateToNull() {
|
||||
|
||||
OCachedApp app = setup();
|
||||
|
||||
// act
|
||||
app.setAppName(null);
|
||||
app.save();
|
||||
|
||||
final OCachedApp foundAfter = DB.find(OCachedApp.class)
|
||||
.where().eq("appName", WILL_CHANGE_TO_NULL)
|
||||
.findOne();
|
||||
|
||||
assertThat(foundAfter).isNull();
|
||||
app.delete();
|
||||
}
|
||||
|
||||
private OCachedApp setup() {
|
||||
OCachedApp app = new OCachedApp(WILL_CHANGE_TO_NULL);
|
||||
app.save();
|
||||
|
||||
final OCachedApp foundBefore = DB.find(OCachedApp.class)
|
||||
.where().eq("appName", WILL_CHANGE_TO_NULL)
|
||||
.findOne();
|
||||
|
||||
assertThat(foundBefore).isNotNull();
|
||||
return app;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user