mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-25 07:57:39 +00:00
Fix for #260 - Trying to insert() or save() an entity with no @Id results in NPE
This commit is contained in:
@@ -67,10 +67,16 @@ public final class InsertMeta {
|
||||
} else {
|
||||
// insert sql for db identity or sequence insert
|
||||
this.concatinatedKey = false;
|
||||
this.identityDbColumns = new String[]{id.getIdentityColumn()};
|
||||
if (id.getIdentityColumn() == null) {
|
||||
this.identityDbColumns = new String[]{};
|
||||
this.supportsGetGeneratedKeys = false;
|
||||
this.selectLastInsertedId = null;
|
||||
} else {
|
||||
this.identityDbColumns = new String[]{id.getIdentityColumn()};
|
||||
this.supportsGetGeneratedKeys = dbPlatform.getDbIdentity().isSupportsGetGeneratedKeys();
|
||||
this.selectLastInsertedId = desc.getSelectLastInsertedId();
|
||||
}
|
||||
this.sqlNullId = genSql(true);
|
||||
this.supportsGetGeneratedKeys = dbPlatform.getDbIdentity().isSupportsGetGeneratedKeys();
|
||||
this.selectLastInsertedId = desc.getSelectLastInsertedId();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.avaje.tests.model.noid;
|
||||
|
||||
import com.avaje.ebean.annotation.CreatedTimestamp;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
@Entity
|
||||
@Table(name="noidbean")
|
||||
public class NoIdBean {
|
||||
|
||||
String name;
|
||||
|
||||
String subject;
|
||||
|
||||
@CreatedTimestamp
|
||||
Timestamp whenCreated;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSubject() {
|
||||
return subject;
|
||||
}
|
||||
|
||||
public void setSubject(String subject) {
|
||||
this.subject = subject;
|
||||
}
|
||||
|
||||
public Timestamp getWhenCreated() {
|
||||
return whenCreated;
|
||||
}
|
||||
|
||||
public void setWhenCreated(Timestamp whenCreated) {
|
||||
this.whenCreated = whenCreated;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.avaje.tests.model.noid;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class TestInsertNoIdBean extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testInsert() {
|
||||
|
||||
|
||||
NoIdBean bean = new NoIdBean();
|
||||
bean.setName("Rocky");
|
||||
bean.setSubject("Blowing up stuff");
|
||||
|
||||
Ebean.save(bean);
|
||||
|
||||
int rowCount = Ebean.find(NoIdBean.class).findRowCount();
|
||||
|
||||
assertTrue("rowCount:"+rowCount, rowCount > 0);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user