i've created an application which uses hibernate inheritance and mapping. There is a parent class named Payment and Child class called Credit. Right i'm trying to insert multiple child values for one single parent id. Like as shown below
|``````````````|
| Payment |
|--------------|
| id | nane |
|-----|--------|
| 1 | mod 1 |
|-----|--------|
| 2 | mod 2 |
|-----|--------|
|````````````````````````````````|
| Credit |
|--------------------------------|
| id | payid | type | mode |
|-----|--------|-------|---------|
| 1 | 1 | 1 | m1 |
|-----|--------|-------|---------|
| 2 | 1 | 4 | m6 |
|-----|--------|-------|---------|
| 3 | 1 | 5 | m5 |
|-----|--------|-------|---------|
| 4 | 1 | 1 | m7 |
|-----|--------|-------|---------|
My code is as given below (For mapping and other details you can check THIS)
Payment tabletcstatus=new Payment();
tabletcstatus.setName("name 123");
session.save(tabletcstatus);
Credit c=new Credit();
c.setMode("mode 1");
c.setPayid(tabletcstatus);
session.save(c);
Credit c1=new Credit();
c1.setMode("mode 2");
c1.setPayid(tabletcstatus);
session.save(c1);
But when i execute i'm getting the following executed
Hibernate: insert into hhh.payment (name) values (?)
Hibernate: insert into hhh.payment (name) values (?)
Hibernate: insert into credit (type, mode, payid) values (?, ?, ?)
Hibernate: insert into hhh.payment (name) values (?)
Hibernate: insert into credit (type, mode, payid) values (?, ?, ?)
here payment is inserted thrice and the two credit has different payid
can anyone please tell me some solution for this.