Hello
I am trying to define default values for some attributes of my model.
Using this model element: ...
class TestElement {
String name = "New Element"
boolean flagged = "true"
}
... with this test code ...
public void testDefault(IEmTracRepoService repo) {
TestElement element = EmTracFactory.eINSTANCE.createTestElement();
Assert.isTrue(element.isFlagged());
Assert.isTrue(element.getName().equals("New Element"));
Diagnostic mDiagnostic = Diagnostician.INSTANCE.validate(element);
Assert.isTrue(mDiagnostic.getSeverity() == Diagnostic.OK);
CDOTransaction transaction = repo.openTransaction();
try {
CDOResource resource = transaction.getOrCreateResource(repo.getResourceName());
resource.getContents().add(element);
transaction.commit();
} catch (CommitException e) {
logger.info("CommitException: {}", e.getLocalizedMessage());
} finally {
transaction.close();
}
}
... the asserts are all true, but the columns "name" and "flagged" are each saved as NULL in the database. The dbstore persists the values as expected with "New Element" and "1", so I presume it is an issue with Hibernate.
I can think of two solutions:
* When persisting an entity, use the default value if the attribute is unset or null
* Use the database default mechanism upon schema generation to define defaults. I. e. with the columnDefinition attribute of the @Column annotation. (Probably needs a refresh of the entity after persist.)
Is one of these features currently implemented? Or do I need to set Hibernate to use "dynamic-insert"?
Greetings
Christoph