ObjectDB ObjectDB

Some details about db behavior

#1

Suppose I have two entities...

A

B -> A

B has a ManyToOne relationship with A.

When my database is empty and I persist a valid B entity (that contains actual A reference) I observe some behavior that I'm not sure I understand.

1. In ObjectDB explorer I see Both B and A Entity classes available in sidebar but B has one row and A has none, I was expecting that one row will be created in A and B will refer to it. Please explain what is happening there? I know about cascade option, and if I use it A will be persisted under A type... but is B referring to that A or it is keeping a copy of that information?

2. In explorer in every column where a complex type is represented in json like manner i see {something, null, null, and allways nulls}, but when i retrieve that field i see that other fields are initialized (which means explorer is showing not right information). 

3. Suppose above mentioned case is persisted successfully, now I remove the A and want B to return null reference (if it is actually referring and not copying information of A) when retrieved through repository, but it actually contains that A object. Is every single B persisted keeping copy of A? how do I achieve that when A is removed all objects referring to it will have null?

I know that there are many questions but I need to understand how the database manages information as this might be critical for the application and performance.

If there are any other materials (books articles) that might help me with this please link them.

Regards

edit
delete
#2

If A is an entity class (and not an embeddable class) after persisting a B instance that references an A instance (with cascading enabled), you should see an A instance in the database. If A is an embeddable class the content of A will be persisted as part of the B instance.

When that A instance is removed you should also update the reference from B accordingly. Otherwise, the behavior depends on who is the relationship owner. If B is the owner you will have a broken reference to a non existing A object that was deleted, which is very bad. If A is the owner, B will be updated to reference a null value automatically on the next time it is loaded or refreshed from the database. But in both cases, portable JPA applications are expected to update both sides of the relationship.

These rules are described in JPA books and in the JPA specification, and most of them also in the ObjectDB manual.

Please try to demonstrate further questions using simple test cases, or sample database (and particularly the Explorer view situation that you described above).

ObjectDB Support
edit
delete

Reply

To post on this website please sign in.