Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO/Hibernate] Default values are not recognized
[CDO/Hibernate] Default values are not recognized [message #903025] Tue, 21 August 2012 16:41 Go to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
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 21:45 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
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
Re: [CDO/Hibernate] Default values are not recognized [message #903136 is a reply to message #903098] Wed, 22 August 2012 07:47 Go to previous message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
Bug 387752
Previous Topic:How to read transient EAttibute?
Next Topic:EMF-Compare Diffs as Command?
Goto Forum:
  


Current Time: Fri Apr 26 03:45:52 GMT 2024

Powered by FUDForum. Page generated in 0.03382 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top