Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » TENEO - ID is coming as null(MySQLIntegrityConstraintViolationException, ID cannot be null.)
TENEO - ID is coming as null [message #1162356] Wed, 30 October 2013 10:19 Go to next message
Chandre Gowda is currently offline Chandre GowdaFriend
Messages: 56
Registered: April 2013
Member
Hi,
I have an EMF model A which refernces Model B. B has list of models c which is of non containement relationship. Iam trying to persist Model A into database using TENEO framework.
I have set following property
PersistenceOptions.FETCH_ASSOCIATION_EXTRA_LAZY as true.

Whenever i try to persist Model A iam getting following error.

com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'B_id' cannot be null.

Plese let me know what is causing the above error.

Thanks
Chandru
Re: TENEO - ID is coming as null [message #1163781 is a reply to message #1162356] Thu, 31 October 2013 07:55 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Chandre,
Not sure but I guess you are not using auto-generated primary keys, I guess. Or maybe in this case you can also check
the cascade settings of the A-->B association. Maybe persist/create is not cascaded.

For info on cascade settings the Hibernate/JPA docs can tell you more.

gr. Martin

On 10/30/2013 11:19 AM, Chandre Gowda wrote:
> Hi,
> I have an EMF model A which refernces Model B. B has list of models c which is of non containement relationship. Iam
> trying to persist Model A into database using TENEO framework. I have set following property
> PersistenceOptions.FETCH_ASSOCIATION_EXTRA_LAZY as true.
>
> Whenever i try to persist Model A iam getting following error.
>
> com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'B_id' cannot be null.
> Plese let me know what is causing the above error.
>
> Thanks
> Chandru


--

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: TENEO - ID is coming as null [message #1164111 is a reply to message #1163781] Thu, 31 October 2013 12:48 Go to previous messageGo to next message
Chandre Gowda is currently offline Chandre GowdaFriend
Messages: 56
Registered: April 2013
Member
Thanks Martin.
Iam using autogenerated id(e_id).
I have set following cascade policy while intializing the DATASTORE.

PersistenceOptions.CASCADE_POLICY_ON_NON_CONTAINMENT, "REFRESH,PERSIST,MERGE".

The above error comes if i set following property as true.
PersistenceOptions.FETCH_ASSOCIATION_EXTRA_LAZY, "true"

If i set PersistenceOptions.FETCH_ASSOCIATION_EXTRA_LAZY as false,
then records will be inserted into superclass table(A) and association table.
But i will get other error as 'lazy initialization failed-session closed'.
SO i want to fetch all the attributes(including containement and noncontainement)
at once.

Am i missing any options that needs to be set during initialization..?

[Updated on: Thu, 31 October 2013 13:05]

Report message to a moderator

Re: TENEO - ID is coming as null [message #1164723 is a reply to message #1164111] Thu, 31 October 2013 21:57 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Chandre,
The extra lazy option is for performance reasons. So I guess you should first get everything working without this and
other options. Setting cascade options makes sense.

I think it is best if you first increase your hibernate knowledge. It seems that most questions are related on how to
handle association loading and such. There are many blog posts on various hibernate topics on the net.

Also read the Hibernate docs thoroughly and search for things like long transactions/sessions, or this one:
https://community.jboss.org/wiki/OpenSessionInView

gr. Martin

On 10/31/2013 01:48 PM, Chandre Gowda wrote:
> Thanks Martin. I have set following cascade policy while intializing the DATASTORE.
>
> PersistenceOptions.CASCADE_POLICY_ON_NON_CONTAINMENT, "REFRESH,PERSIST,MERGE".
>
> The above error comes if i set following property as true.
> PersistenceOptions.FETCH_ASSOCIATION_EXTRA_LAZY, "true"
>
> If i set PersistenceOptions.FETCH_ASSOCIATION_EXTRA_LAZY as false, then records will be inserted into superclass
> table(A) and association table.
> But i will get other error as 'lazy initialization failed-session closed'.
> SO i want to fetch all the attributes(including containement and noncontainement)
> at once.
>
> Am i missing any options that needs to be set during initialization..?
>


--

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: TENEO - ID is coming as null [message #1165943 is a reply to message #1164723] Fri, 01 November 2013 17:08 Go to previous messageGo to next message
Chandre Gowda is currently offline Chandre GowdaFriend
Messages: 56
Registered: April 2013
Member
Thanks Martin.I had gone through the opensessionInView filter and other hibernate articles on lazy loading. I could try those options, but i wanted to try loading all the containement and non-containement attributes at once even if performance is going to be down. Because currently our EMF Metamodel is bit complex. So Setting the following option
PersistenceOptions.FETCH_ASSOCIATION_EXTRA_LAZY, "true"
giving error as 'B_e_id cannot be null' during save(object) operation(B is non-containement relationship with A).
Can we try fetching noncontainement and containement attributes at once in TENEO or am i missing any option that needs to be set.
Re: TENEO - ID is coming as null [message #1169570 is a reply to message #1165943] Mon, 04 November 2013 03:56 Go to previous messageGo to next message
Chandre Gowda is currently offline Chandre GowdaFriend
Messages: 56
Registered: April 2013
Member
Oh.. I was assuming
PersistenceOptions.FETCH_ASSOCIATION_EXTRA_LAZY, "true"
would fetch all the non containement asscoiations at once without requiring any sessionfilter. Actually this flag makes the association loading extra lazy. I want to know whether any option available in TENEO which fetches all non containement at once without using any session filter and not taking advantage of Hibernate lazy loading.
Re: TENEO - ID is coming as null [message #1169857 is a reply to message #1169570] Mon, 04 November 2013 08:32 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Chandre,
There is no specific option to eagerly load all the associations (many and single). What you can do is annotate the
ecore model before you initialize the datastore. So write some code which traverses the model and programmatically add
annotations to it.
Then you can use standard JPA annotations to force eager loading.

gr. Martin

On 11/04/2013 04:56 AM, Chandre Gowda wrote:
> Oh.. I was assuming PersistenceOptions.FETCH_ASSOCIATION_EXTRA_LAZY, "true" would fetch all the non containement
> asscoiations at once without requiring any sessionfilter. Actually this flag makes the association loading extra lazy. I
> want to know whether any option available in TENEO which fetches all non containement at once without using any session
> filter and not taking advantage of Hibernate lazy loading.


--

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: TENEO - ID is coming as null [message #1220925 is a reply to message #1169857] Mon, 16 December 2013 08:16 Go to previous messageGo to next message
Chandre Gowda is currently offline Chandre GowdaFriend
Messages: 56
Registered: April 2013
Member
Iam sorry for taking so much time.
I couldn't understand 'annotating the ecore model. I have a class 'LOG' which has noncontainement attribute 'entries'(list). I want to load this attribute eagerly. Please let me know how to accomplish this.

Thanks
Chandru
Re: TENEO - ID is coming as null [message #1220941 is a reply to message #1220925] Mon, 16 December 2013 09:32 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Chandre,
Annotating the ecore model means specifying the JPA annotations in the EAnnotations of the model. So not in the java
code, but in the ecore or xsd file.

Teneo has fairly extensive wiki content on this:
http://wiki.eclipse.org/Teneo/Hibernate#Model_Relational_Mapping_with_EJB3.2FJPA_Annotations

Can you go through all these pages? If you have remaining questions, can you then ask specific questions on which
specific part of these wiki documents are not clear?
This will also help to further improve the wiki.

gr. Martin

On 12/16/2013 09:16 AM, Chandre Gowda wrote:
> Iam sorry for taking so much time.
> I couldn't understand 'annotating the ecore model. I have a class 'LOG' which has noncontainement attribute
> 'entries'(list). I want to load this attribute eagerly. Please let me know how to accomplish this.
>
> Thanks
> Chandru


--

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: TENEO - ID is coming as null [message #1221219 is a reply to message #1220941] Tue, 17 December 2013 06:22 Go to previous messageGo to next message
Chandre Gowda is currently offline Chandre GowdaFriend
Messages: 56
Registered: April 2013
Member
Thanks Martin.
I have edited ecore in text editor and placed following code for that attribute.

<eAnnotations source="teneo.jpa">
<details key="appinfo" value="@OneToMany(fetch=FetchType.EAGER)"/>
</eAnnotations>.

Its working now. The attribute is loading eagerly.
However I couldn't understand the other way of annotating i.e through XML files.
How do we link ecore model and xml file ?


Thanks
Chandru
Re: TENEO - ID is coming as null [message #1221230 is a reply to message #1221219] Tue, 17 December 2013 07:04 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Chandre,
It was mentioned in this wiki page, but I changed the wording a bit to make it more explicit, see the (new) second
paragraph here:
https://wiki.eclipse.org/Teneo/Hibernate/ModelRelational/Annotations_Format#JPA_Annotations_in_XML

You don't need to edit the ecore manually, you can also add eannotations in the ecore editor, right click on different
nodes, there should be an option to add an eannotation child somewhere.

gr. Martin

On 12/17/2013 07:22 AM, Chandre Gowda wrote:
> Thanks Martin.
> I have edited ecore in text editor and placed following code for that attribute.
>
> <eAnnotations source="teneo.jpa">
> <details key="appinfo" value="@OneToMany(fetch=FetchType.EAGER)"/>
> </eAnnotations>.
>
> Its working now. The attribute is loading eagerly. However I couldn't understand the other way of annotating i.e through
> XML files.
> How do we link ecore model and xml file ?
>
>
> Thanks
> Chandru


--

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
Previous Topic:[Teneo] inheritance mapping - cannot alter default strategy
Next Topic:Declaration of super interfaces during code generation
Goto Forum:
  


Current Time: Thu Mar 28 23:23:39 GMT 2024

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

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

Back to the top