Skip to content
Advertisement

How to add entity to the databse without adding related entitiy in DB as well?

I have a problem adding one entity using JPA save without error :

JdbcSQLIntegrityConstraintViolationException: NULL not allowed for column

because i add empty entity to the object i want to save. how can i save one entity and tell it’s related one to ignore this transaction?

For example i have student and i have student_info OneToOne Relationship. I want to save student and not assign information to him yet, but my student_info tells me : hey student_info column 1 can not be null.

Advertisement

Answer

You can’t!

If there is a constraint on the database like Not Null, primary or foreign key then you can only save the data to this table when the constraints are fulfilled.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement