[CDO/Hibernate] Default values are not recognized [message #903025] |
Tue, 21 August 2012 12:41  |
Eclipse User |
|
|
|
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
|
|
|
Re: [CDO/Hibernate] Default values are not recognized [message #903098 is a reply to message #903025] |
Tue, 21 August 2012 17:45   |
Eclipse User |
|
|
|
Hi Christoph,
The behavior should be the same as the dbstore. Can you enter a bugzilla for this on CDO 4.1/4.2?
gr. Martin
On 08/21/2012 06:41 PM, Christoph Keimel wrote:
> 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
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
|
|
|
|
Powered by
FUDForum. Page generated in 0.03837 seconds