Hello Gary, love your videos. I have question regarding OneToOne relation. (I will explain my setup) I have TableA and TableB. TableA is my primary table, TableB is my additonal table. OneToOne relation is done like this: in table A I have property tableB which doesn't have JoinColumn option. (I do not want to have TableB's ID stored in TableA) Via tableB property I am accessing to TableB's properties. TableB have tableA(unique key) property which has JoinCoulmn option, and in TableB I want to store TableA's ID. Problem occurs when I want to update data eg. I want to send PUT request and in that request I am sending data for TableA and for TableB (via tableA property). I got unique constraint violations, because it tries to POST data (which I am sending via request) even though it has the same data written into the data base. I tried to manage this error, but later I got "entity not managed" error. So everything else works, just PUT/UPDATE request is causing problems. I also tried your Customer-Cart variation, then it will do the data update but there is no connection between theese two tables, my customer_id in cart table is NULL. Every other time I send update data for the same ID of Customer it creates new Cart without connection to Customer. Best wishes.
@GaryClarkeTech2 жыл бұрын
It's a good question. I'll try to find an example and come back to you
@ricohumme43283 жыл бұрын
Hi Gary, what I am missing in this video is the why should you use / not use one to one relations. I believe this is a key differentiator between one to one and many to one relations. Other than that, good info on this topic.
@GaryClarkeTech3 жыл бұрын
Hi Rico...good point, I should make the distinction clear. I use one to ones rarely because the question I always end up asking myself is 'Why create a separate table in the first place? Can't I just add extra fields to the parent?' The answer is usually yes. I will use one to ones where the extra fields are going to be applicable to less than half of the records and I want to avoid redundant / empty fields in the majority of records. One to many is a lot simpler because if you need it, you need it; it's not optional.
@hrefamid95632 жыл бұрын
How does cascade persiste and remove work on a OneToOne relation? On which side can you or do you have to specify it? I’m wondering the same on a ManyToMany, I think I’ve figured it out for a ManyToOne 🤔
@GaryClarkeTech2 жыл бұрын
I wouldn't do this with a many to many..think about possible consequences..you might remove records that have a relationship with others.