John Jerrby
John Jerrby

Reputation: 1703

save entity with null reference

I would like to know if for example I have entity like customer and customer addresss and address is a reference in in customer what will happen if I dont find match with the entities keys some instance of customer will need to be saved with address null what will happen in the commit ,i will get dump?

Upvotes: 0

Views: 59

Answers (2)

evgenyl
evgenyl

Reputation: 8117

Imo, if you db allows nulls in the address column (and no FK constraints exists), it will save nulls. Else, it should fail.

Upvotes: 1

AlexR
AlexR

Reputation: 115378

It depends on what technique are you using and what DB schema have you defined. Typically object graph is represented in relational DB as a number of tables with foreign keys that represent references between objects. If the field (the FK) is nullable, so you can save customer without address. Otherwise constraint violation exception will be thrown.

If you need more information please post some of your code and explain what is the persistence technology that you are using.

Upvotes: 1

Related Questions