Topics

MIssing foreign key on children - except on those of last parent added to db


Trond Arild Lode Tobiassen Heidelberg
 
Edited

Hi 

I have this code:

@Entity(name = "ABSTRACT_MESSAGE_TABLE")
@DiscriminatorColumn(length=64)
public abstract class AbstractMessage<T extends AbstractMessage<T, U, X>, U extends StartLine<U>, X extends AbstractPart<X>>
implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE)
private Long id;
 
public Long getId() {
return id;
}
 
private void setId(Long id) {
this.id = id;
}
 
/**
*/
private static final long serialVersionUID = xxxxxxxxxxxxxxxxxxxxxxxxxxL;
 
protected AbstractMessage() {
}
 
@OneToOne(optional = false, cascade = CascadeType.ALL)
@JoinColumn(name = "START_LINE", unique = false, nullable = true, updatable = false)
protected U startLine;
 
 
public U getStartLine() {
return startLine;
}
 
protected void setStartLine(U startLine) {
this.startLine = startLine;
}
 
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "MESSAGE_ID", nullable = true, unique = false, updatable = false)
protected List<AbstractHeaderField<?>> sipHeadersList;


It is MESSAGE_ID which is filled in only for last parent.

Does anyone know what might be wrong? Same errror for glassfish 4.1 and 5.0.

Here are table contents:
ABSTRACT_MESSAGE_TABLE:

ID ...
63 REGISTER_EMPTY_PART_TABLE 0 64 62
119 SIP401_UNAUTHORIZED_EMPTY_PART_TABLE 0 120 62
190 REGISTER_EMPTY_PART_TABLE 0 191 189
246 SIP401_UNAUTHORIZED_EMPTY_PART_TABLE 0 247 189
323 REGISTER_EMPTY_PART_TABLE 0 324 322
416 SIP200_OK_EMPTY_PART_TABLE 0 417 322
476 REGISTER_EMPTY_PART_TABLE 0 477 475
583 SIP200_OK_EMPTY_PART_TABLE 0 584 582

ABSTRACT_HEADER_FIELD_TABLE:

ID ...... MESSAGE_ID (last column either null - not visible - or 583 marked in bold)
101 ALLOW_TABLE 0
142 ALLOW_TABLE 0
158 CSEQ_TABLE 0 9350 0
104 CSEQ_TABLE 0 9350 0
137 CSEQ_TABLE 0 9350 0
91 CSEQ_TABLE 0 9350 0
89 CALL_ID_TABLE 90 0
135 CALL_ID_TABLE 136 0
95 CONTACT_TABLE 0
143 CONTENT_LENGTH_TABLE 0 0
102 CONTENT_LENGTH_TABLE 0 0
141 EXPIRES_TABLE 900 0
100 EXPIRES_TABLE 900 0
105 FROM_TABLE 106 0
159 FROM_TABLE 160 0
82 FROM_TABLE 83 0
131 FROM_TABLE 132 0
81 MAX_FORWARDS_TABLE 70 0
74 ROUTE_TABLE 0
86 TO_TABLE 87 0
144 TO_TABLE 145 0
110 TO_TABLE 111 0
163 TO_TABLE 164 0
92 USER_AGENT_TABLE 0
138 USER_AGENT_TABLE 0
67 VIA_TABLE 0
122 VIA_TABLE 0
149 WWW_AUTHENTICATE_TABLE 0
177 CSEQ_TABLE 0 9350 0
178 TO_TABLE 179 0
228 ALLOW_TABLE 0
269 ALLOW_TABLE 0
264 CSEQ_TABLE 0 9350 0
231 CSEQ_TABLE 0 9350 0
285 CSEQ_TABLE 0 9350 0
218 CSEQ_TABLE 0 9350 0
216 CALL_ID_TABLE 217 0
262 CALL_ID_TABLE 263 0
222 CONTACT_TABLE 0
229 CONTENT_LENGTH_TABLE 0 0
270 CONTENT_LENGTH_TABLE 0 0
227 EXPIRES_TABLE 900 0
268 EXPIRES_TABLE 900 0
209 FROM_TABLE 210 0
232 FROM_TABLE 233 0
286 FROM_TABLE 287 0
258 FROM_TABLE 259 0
208 MAX_FORWARDS_TABLE 70 0
201 ROUTE_TABLE 0
271 TO_TABLE 272 0
213 TO_TABLE 214 0
290 TO_TABLE 291 0
237 TO_TABLE 238 0
219 USER_AGENT_TABLE 0
265 USER_AGENT_TABLE 0
249 VIA_TABLE 0
194 VIA_TABLE 0
276 WWW_AUTHENTICATE_TABLE 0
310 CSEQ_TABLE 0 9350 0
304 CSEQ_TABLE 0 9350 0
311 TO_TABLE 312 0
305 TO_TABLE 306 0
361 ALLOW_TABLE 0
362 AUTHORIZATION_TABLE 0
397 CSEQ_TABLE 0 9350 0
375 CSEQ_TABLE 0 9351 0
391 CSEQ_TABLE 0 9350 0
403 CSEQ_TABLE 0 9351 0
351 CSEQ_TABLE 0 9351 0
349 CALL_ID_TABLE 350 0
355 CONTACT_TABLE 0
373 CONTENT_LENGTH_TABLE 0 0
360 EXPIRES_TABLE 900 0
342 FROM_TABLE 343 0
376 FROM_TABLE 377 0
341 MAX_FORWARDS_TABLE 70 0
334 ROUTE_TABLE 0
392 TO_TABLE 393 0
398 TO_TABLE 399 0
381 TO_TABLE 382 0
346 TO_TABLE 347 0
404 TO_TABLE 405 0
352 USER_AGENT_TABLE 0
327 VIA_TABLE 0
444 ALLOW_TABLE 0
434 CSEQ_TABLE 0 9351 0
452 CSEQ_TABLE 0 9351 0
410 CSEQ_TABLE 0 9351 0
432 CALL_ID_TABLE 433 0
438 CONTACT_TABLE 0
445 CONTENT_LENGTH_TABLE 0 0
443 EXPIRES_TABLE 900 0
428 FROM_TABLE 429 0
453 FROM_TABLE 454 0
411 TO_TABLE 412 0
446 TO_TABLE 447 0
457 TO_TABLE 458 0
435 USER_AGENT_TABLE 0
419 VIA_TABLE 0
514 ALLOW_TABLE 0
515 AUTHORIZATION_TABLE 0
504 CSEQ_TABLE 0 9351 0
554 CSEQ_TABLE 0 9350 0
548 CSEQ_TABLE 0 9351 0
470 CSEQ_TABLE 0 9350 0
544 CSEQ_TABLE 0 9350 0
560 CSEQ_TABLE 0 9351 0
528 CSEQ_TABLE 0 9351 0
502 CALL_ID_TABLE 503 0
508 CONTACT_TABLE 0
526 CONTENT_LENGTH_TABLE 0 0
513 EXPIRES_TABLE 900 0
495 FROM_TABLE 496 0
529 FROM_TABLE 530 0
494 MAX_FORWARDS_TABLE 70 0
487 ROUTE_TABLE 0
499 TO_TABLE 500 0
471 TO_TABLE 472 0
549 TO_TABLE 550 0
561 TO_TABLE 562 0
534 TO_TABLE 535 0
545 TO_TABLE 546 0
555 TO_TABLE 556 0
505 USER_AGENT_TABLE 0
480 VIA_TABLE 0
611 ALLOW_TABLE 0 583
601 CSEQ_TABLE 0 9351 0 583
569 CSEQ_TABLE 0 9351 0
574 CSEQ_TABLE 0 9350 0
565 CSEQ_TABLE 0 9350 0
619 CSEQ_TABLE 0 9351 0
578 CSEQ_TABLE 0 9351 0
599 CALL_ID_TABLE 600 0 583
605 CONTACT_TABLE 0 583
612 CONTENT_LENGTH_TABLE 0 0 583
610 EXPIRES_TABLE 900 0 583
620 FROM_TABLE 621 0
595 FROM_TABLE 596 0 583
613 TO_TABLE 614 0 583
624 TO_TABLE 625 0
570 TO_TABLE 571 0
575 TO_TABLE 576 0
566 TO_TABLE 567 0
579 TO_TABLE 580 0
602 USER_AGENT_TABLE 0 583
586 VIA_TABLE 0 583
 
Glassfish 4.1 and 5.0
Java SE 8
Java EE 7
Win 7
Oracle 12c
ojdbc14 and same with ojdbc7 (12.1.0.1)


You can see that message with id 416 is identical to 583 (and the result of the exact same process). I wonder why this happens.
I have also seen that a 401 message is saved correctly.
It might be helpful to mention that the problematic rows are children of children which parent is correctly saved (updated with foreign key). It is a mq message which does the database work.


Trond Arild Lode Tobiassen Heidelberg
 

On Tue, Dec 5, 2017 at 02:19 am, Trond Arild Lode Tobiassen Heidelberg wrote:

changed form this:
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "MESSAGE_ID", nullable = true, unique = false, updatable = false)
protected List<AbstractHeaderField<?>> sipHeadersList;
To this:
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "MESSAGE_ID", nullable = true, unique = false, updatable = true)
protected List<AbstractHeaderField<?>> sipHeadersList;

to help allow update of rows with the foreign key. But alas in vain.