Question about auto-commit behavior.

3
Does this include 1-1 associations w/ owner set as "Both" ? Everything I've read about auto-commit behavior suggests some sort of improper modeling (like having a child set as the owner of an association to the parent, then committing the child before the parent), but nothing about 1-1 associations. Here's my scenario: I have an entity called "JobInformation" with a 1-* from Account (an account can have multiple jobs), and a 1-1 association from Account to JobInformation called "PrimaryJob" so we can show people's main job in data grids. We run a scheduled event to pull job data from our HR System and sync with our system, but it keeps failing because of autocommit errors, however if we run manually, it works great. Note: accounts objects are not being created during this process.                                      
asked
3 answers
4

Hi Jordan,

When you have two objects that are associated 1 to 1 to each other then they will both be committed if you commit either one. This behaves similarly to the what the documentation describes between a child as the owner of the association to the parent. When the child is committed the parent is also committed because it was the owner of the association. In a 1 to 1 since they are both the owner, you can commit either one and the other will be committed. 

You can test this by creating two entities with a 1 to 1 association and debugging them as you set the association to one another. 

In this example I have an entity called "entity" and thats associatied to "entity_2" by a 1 to 1 association. Before I create entity_2 and associated it to entity, the association is empty. Once I created entity_2 the association on both sides are set. 

 

 

Then if I were to commit one of these objects, the other will be committed as well.

 

 

Hope this helps!

answered
4

For future reference:

When object A has a relation directed to object B (either * – 1 or * – *). When only object A is committed, object B is autocommitted

When object A has an undirected relation with object B (either 1 – 1 or * – *). When only object A is committed, object B is autocommitted

When object B has a relation directed to object A (either * – 1 or * – *). When only object A is committed, object B stays instantiated (not autocommitted)

 

This is especially important with entities that inherit from filedocument. Since Mendix commits the filedocument itself after uploading, all entities the filedocument child relates to will be autocommitted.

answered
0

Is this also true for relations between non persistent and persistent objects?

answered