Guest User

Untitled

a guest
Dec 14th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. /// My trigger looks like this
  2. CREATE OR REPLACE TRIGGER FILE_BRI
  3. BEFORE INSERT
  4. ON FILE
  5. FOR EACH ROW
  6. BEGIN
  7. SELECT FILE_SEQ.NEXTVAL INTO :NEW.ID FROM DUAL;
  8. END;
  9. ///
  10.  
  11. public class FILE implements Serializable {
  12. @Id
  13. @SequenceGenerator(
  14. name = "FILE_SEQ",
  15. sequenceName = "FILE_SEQ",
  16. allocationSize = 1)
  17. @GeneratedValue(
  18. strategy = GenerationType.SEQUENCE,
  19. generator = "FILE_SEQ"
  20. )
  21. private long id;
  22. }
  23.  
  24. public class ServiceA () {
  25.  
  26. @Transactional(propagation = REQUIRES_NEW, isolation = READ_COMMITTED)
  27. public File insertFile() {
  28. // Below line returns the inserted File object with ID as '58496'
  29. return fileRepository.save(file)
  30. }
  31.  
  32. @Transactional(propagation = REQUIRES_NEW, isolation = READ_COMMITTED)
  33. public AccessControl insertAccessControl() {
  34. // Below line results in 'SQLIntegrityConstraintViolationException' (full error at the bottom of this post)
  35. return accessControlRepository.save(accessControlFile)
  36. }
  37. }
  38.  
  39. Public class FileProcessor() {
  40. ServiceA serviceA;
  41. public void someMethod() {
  42. // insert the file and get the inserted record
  43. File insertedFile = serviceA.insertFile(file);
  44.  
  45. // get the ID from the inserted file and make another insert into another table
  46. serviceA.insertAccessControl(insertedFile.getId()); // inserted file ID is '58496'
  47. }
  48. }
Add Comment
Please, Sign In to add comment