Giter VIP home page Giter VIP logo

njnareshjoshi / articles Goto Github PK

View Code? Open in Web Editor NEW
119.0 12.0 120.0 4.52 MB

This repository along with the exercises repository (https://github.com/njnareshjoshi/exercises) contains coding examples for my blog ProgrammingMitra

Home Page: https://www.programmingmitra.com

License: Apache License 2.0

Java 83.44% JavaScript 4.25% Dockerfile 0.20% HTML 11.68% TSQL 0.43%
java java-8 java-cloning spring spring-data jpa-auditing java-serialization

articles's Issues

Strange behaviour with UUID key generators in spring-data-jpa-auditing

Hello
Thanks for the greate tutorial
I'm experience the interesting issue if I change the id from Integer to UUID in File class in spring-data-jpa-auditing project :

    @Id
    @GeneratedValue (generator = "UUID")
    @GenericGenerator(            name = "UUID",
            strategy = "org.hibernate.id.UUIDGenerator"
    )
    private UUID id;

The exception I'm getting is :

Caused by: org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint ["PRIMARY_KEY_2 ON PUBLIC.FILE(ID) VALUES (X'1797c3aded61453d891874d491356c9c', 1)"; SQL statement:
insert into file (created_by, created_date, last_modified_by, last_modified_date, content, name, id) values (?, ?, ?, ?, ?, ?, ?) [23505-197]]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement

And I see two insert statements for File entity.
To reproduce, just change the id to be UUID with the annotations I've shown before ,tweak getter and seeter ,change from @PrePersist to @PostPersist :

public class FileEntityListener {

    @PostPersist //  @PrePersist 
    public void prePersist(File target) {
        perform(target, INSERTED);
    }
}

and run.
Can you think about the reason and possible solution ?
Thanks

Getting Referential integrity constraint violation exception when trying to delete parent (file) entity

Hello Naresh - thanks for the post, which is of great assistance.

Currently, using Spring boot 2.3 with jpa. I tried to write my own poc with Book and BookHistory entity (corresponding to File and FileHistory), with other audit * classes same. The BookHistory is manyToOne with Book.

The add/insert fine are logging correctly in BookHistory table, it is just that when I try to delete a 'Book', the operation is failing as hibernate seems to be complaining because it is not willing to leave the record "orphaned" in BookHistory (when a Book is deleted). By any chance you faced similar issue?

This is exception trace
org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException: Referential integrity constraint violation: "FKABA5IOAFYJ1YQA0TBC27TV1EB: PUBLIC.BOOK_HISTORY FOREIGN KEY(BOOK_ID) REFERENCES PUBLIC.BOOK(BOOK_ID) (1)"; SQL statement:
delete from book where book_id=? [23503-200]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:459) ~[h2-1.4.200.jar:1.4.200]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:429) ~[h2-1.4.200.jar:1.4.200]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.