We have two persistence objects where a hasMany b. So a is a property of b.

Now we are creating an object of type b and asign the corresponding a-object to b.

b.a = a;

Then we try to save the newly created b object via:

ivy.persistence.persistenceUnit.merge(b);

Then it throws an error that the ForeignKey of a in table b cannot be null. But in the debugger object a is assigned correctly to object b.

In which pitfall did I run here?

asked 29.04.2014 at 08:45

Nikel%20Weis's gravatar image

Nikel Weis
(suspended)
accept rate: 57%

I think your problem is hibernate related. I guess you did not save 'a' first. so there is no actual (database wise) connection to b. But to be able to save 'b' with a reference to 'a' you must save 'a' first. So if you do save 'a' first and then execute your line it should be fine.

(29.04.2014 at 13:37) Daniel Oechslin Daniel%20Oechslin's gravatar image

Thanks for your reply. A already exists in the database. The a-object is determined by object b which contains the id of a (contents of object b are from a third-party system and the object shall be created in the database). With that id given object a is fetched from the database. So that should actually not be the problem.

(29.04.2014 at 13:39) Nikel Weis Nikel%20Weis's gravatar image

Hmm... ok it was indeed an Xpert.ivy related pitfall. Kind of embarrassing but I want to avoid anyone else spends time on that. It is possible to set "not insertable" and "not updatable" in the Data Class definition. AND THAT'S WHAT HAPPENS INDEED! No records can be inserted or updated from the program logic layer.

link

answered 30.04.2014 at 09:30

Nikel%20Weis's gravatar image

Nikel Weis
(suspended)
accept rate: 57%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×32

Asked: 29.04.2014 at 08:45

Seen: 2,405 times

Last updated: 30.04.2014 at 09:30