Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// My trigger looks like this
- CREATE OR REPLACE TRIGGER FILE_BRI
- BEFORE INSERT
- ON FILE
- FOR EACH ROW
- BEGIN
- SELECT FILE_SEQ.NEXTVAL INTO :NEW.ID FROM DUAL;
- END;
- ///
- public class FILE implements Serializable {
- @Id
- @SequenceGenerator(
- name = "FILE_SEQ",
- sequenceName = "FILE_SEQ",
- allocationSize = 1)
- @GeneratedValue(
- strategy = GenerationType.SEQUENCE,
- generator = "FILE_SEQ"
- )
- private long id;
- }
- public class ServiceA () {
- @Transactional(propagation = REQUIRES_NEW, isolation = READ_COMMITTED)
- public File insertFile() {
- // Below line returns the inserted File object with ID as '58496'
- return fileRepository.save(file)
- }
- @Transactional(propagation = REQUIRES_NEW, isolation = READ_COMMITTED)
- public AccessControl insertAccessControl() {
- // Below line results in 'SQLIntegrityConstraintViolationException' (full error at the bottom of this post)
- return accessControlRepository.save(accessControlFile)
- }
- }
- Public class FileProcessor() {
- ServiceA serviceA;
- public void someMethod() {
- // insert the file and get the inserted record
- File insertedFile = serviceA.insertFile(file);
- // get the ID from the inserted file and make another insert into another table
- serviceA.insertAccessControl(insertedFile.getId()); // inserted file ID is '58496'
- }
- }
Add Comment
Please, Sign In to add comment