diff --git a/src/main/java/com/avaje/ebean/dbmigration/model/build/ModelBuildPropertyVisitor.java b/src/main/java/com/avaje/ebean/dbmigration/model/build/ModelBuildPropertyVisitor.java index 60185d7ab..2ad3925e2 100644 --- a/src/main/java/com/avaje/ebean/dbmigration/model/build/ModelBuildPropertyVisitor.java +++ b/src/main/java/com/avaje/ebean/dbmigration/model/build/ModelBuildPropertyVisitor.java @@ -236,6 +236,7 @@ public class ModelBuildPropertyVisitor extends BaseTablePropertyVisitor { col.setDefaultValue(p.getDbColumnDefault()); col.setComment(p.getDbComment()); col.setDraftOnly(p.isDraftOnly()); + col.setHistoryExclude(p.isExcludedFromHistory()); if (p.isId()) { col.setPrimaryKey(true); diff --git a/src/test/java/com/avaje/tests/history/TestHistoryInsert.java b/src/test/java/com/avaje/tests/history/TestHistoryInsert.java index c3203fc5d..7c554ab59 100644 --- a/src/test/java/com/avaje/tests/history/TestHistoryInsert.java +++ b/src/test/java/com/avaje/tests/history/TestHistoryInsert.java @@ -19,16 +19,14 @@ public class TestHistoryInsert extends BaseTestCase { @Test public void test() throws InterruptedException { - SpiEbeanServer defaultServer = (SpiEbeanServer)Ebean.getDefaultServer(); - if (!"h2".equals(defaultServer.getDatabasePlatform().getName())) { - // Oracle for example uses total recall so we can select the explicit - // history tables as we do in this test + if (!isH2() && !isPostgres()) { return; } User user = new User(); user.setName("Jim"); user.setEmail("one@email.com"); + user.setPasswordHash("someHash"); Ebean.save(user); @@ -41,6 +39,7 @@ public class TestHistoryInsert extends BaseTestCase { assertThat(versions).hasSize(1); user.setName("Jim v2"); + user.setPasswordHash("anotherHash"); Thread.sleep(10); // wait, to ensure that whenModified differs Ebean.save(user); @@ -88,7 +87,7 @@ public class TestHistoryInsert extends BaseTestCase { * Use SqlQuery to query the history table directly. */ private List fetchHistory(User user) { - SqlQuery sqlQuery = Ebean.createSqlQuery("select * from c_user_history where id = :id order by sys_period_start"); + SqlQuery sqlQuery = Ebean.createSqlQuery("select * from c_user_history where id = :id order by when_modified"); sqlQuery.setParameter("id", user.getId()); return sqlQuery.findList(); } diff --git a/src/test/java/com/avaje/tests/model/converstation/User.java b/src/test/java/com/avaje/tests/model/converstation/User.java index 3e365901c..350fa74bc 100644 --- a/src/test/java/com/avaje/tests/model/converstation/User.java +++ b/src/test/java/com/avaje/tests/model/converstation/User.java @@ -5,8 +5,12 @@ import javax.persistence.ManyToOne; import javax.persistence.Table; import com.avaje.ebean.annotation.History; +import com.avaje.ebean.annotation.HistoryExclude; +import com.avaje.ebean.annotation.WhenModified; import com.avaje.tests.model.BaseModel; +import java.sql.Timestamp; + @History @Entity @Table(name="c_user") @@ -18,9 +22,17 @@ public class User extends BaseModel { String email; + @HistoryExclude + String passwordHash; + @ManyToOne Group group; - + + @WhenModified + Timestamp whenModified; + + public User() { + } public boolean isInactive() { return inactive; @@ -53,5 +65,22 @@ public class User extends BaseModel { public void setGroup(Group group) { this.group = group; } - + + public String getPasswordHash() { + return passwordHash; + } + + public void setPasswordHash(String passwordHash) { + this.passwordHash = passwordHash; + } + + @Override + public Timestamp getWhenModified() { + return whenModified; + } + + @Override + public void setWhenModified(Timestamp whenModified) { + this.whenModified = whenModified; + } }