How to handle the Foreign key constrain Error in JDBC sink connector?

Viewed 155

Consider I have 2 tables in sink side, eg: Student and Teacher table, where Student table have a TeacherId column that have foreign key relation with Teacher table. Currently, I have separate topics for student and teacher entity and I have 2 sink connectors(for student and teacher topic).

The issue is that

  1. When I insert data in both table(first teacher table and then student table with new inserted teacherId) it will publish messages to kafka topic.
  2. if the student sink connector execute first before teacher sink connector, then the student sink connector task will fail due to foreign key violation(because in sink connector newly created teacher record is didn't fill yet).

(I searched a lot in internet, I didn't find a way to do the same. But some result showing a nested JDBC connector(https://github.com/findinpath/kafka-connect-nested-set-jdbc-sink). When I read the documentation, I didn't understand the content in it. Also, I can't know this will solve my issue.)

How we can solve this ? What approach I need to do in my implementation?

0 Answers
Related