The High-Performance Java Persistence book and video course code examples

Overview

High-Performance Java Persistence

The High-Performance Java Persistence book and video course code examples. I wrote this article about this repository since it's one of the best way to test JDBC, JPA, Hibernate or even jOOQ code. Or, if you prefer videos, you can watch this presentation on YouTube.

Are you struggling with application performance issues?

Hypersistence Optimizer

Imagine having a tool that can automatically detect if you are using JPA and Hibernate properly. No more performance issues, no more having to spend countless hours trying to figure out why your application is barely crawling.

Imagine discovering early during the development cycle that you are using suboptimal mappings and entity relationships or that you are missing performance-related settings.

More, with Hypersistence Optimizer, you can detect all such issues during testing and make sure you don't deploy to production a change that will affect data access layer performance.

Hypersistence Optimizer is the tool you've been long waiting for!

Training

If you are interested in on-site training, I can offer you my High-Performance Java Persistence training which can be adapted to one, two or three days of sessions. For more details, check out my website.

Consulting

If you want me to review your application and provide insight into how you can optimize it to run faster, then check out my consulting page.

High-Performance Java Persistence Video Courses

If you want the fastest way to learn how to speed up a Java database application, then you should definitely enroll in my High-Performance Java Persistence video courses.

High-Performance Java Persistence Book

Or, if you prefer reading books, you are going to love my High-Performance Java Persistence book as well.

High-Performance Java Persistence book High-Performance Java Persistence video course

Java

All examples require at least Java 16 because of the awesome Text Blocks feature, which makes JPQL and SQL queries so much readable.

Maven

You need to use Maven 3.6.2 or newer and configure Maven Toolchains as follows:

  1. You need to create a toolchains.xml file in the Maven Home folder (e.g., %M2_HOME% on Windows, $M2_HOME on Unix based systems). For example, on Windows, the toolchains.xml file is going to be located at this path: c:\Users\%USERNAME%\.m2\toolchains.xml.

  2. Inside the toolchains.xml, you need to define the installation path of Java 13 or newer, as follows:

     <toolchains>
       <toolchain>
         <type>jdk</type>
         <provides>
           <id>Java16</id>
           <version>16</version>
         </provides>
         <configuration>
           <jdkHome>${env.JAVA_HOME_16}</jdkHome>
         </configuration>
       </toolchain>
     </toolchains>
    

In my example, the JAVA_HOME_16 is an environment variable pointing to a local folder where Java 16 is installed.

For more details about using Maven Toolchains, check out this article.

IntelliJ IDEA

On IntelliJ IDEA, the project runs just fine. You will have to make sure to select Java 13 or newer and enable the preview features as illustrated by the following diagram:

HHow to set up IntelliJ IDEA to enable the Java 13 preview features

Eclipse

If you're using Eclipse, you must use the Open JDK compiler and not the Eclipse-based one which suffers from this issue.

However, on Eclipse it has been reported that you need to consider the following configurations. Many thanks to Urs Joss for the hints:

  1. Eclipse does not automatically treat the generated sources by jpamodelgen as source folders. You need to add a dependency on hibernate-jpamodelgen and use the build-helper-maven-plugin to source the folders with the generated sources.
  2. Secondly, the Maven eclipse plugin e2m seems to have an issue with some plugin configurations. Make sure you configure e2m to ignore the false positives issues since the project runs just fine from a Maven command line.

Database setup

The Integration Tests require some external configurations:

Docker-compose Database setup

Use the provided docker compose file in the docker subdirectory.

The following manual steps are necessary:

For MS-SQL:

docker exec -it sql1 "bash"
...       
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "adminPassword1!"
...
CREATE DATABASE high_performance_java_persistence
GO

ALTER LOGIN sa
WITH CHECK_POLICY = OFF
GO

ALTER LOGIN sa
WITH PASSWORD = 'admin'
GO

exit
...
exit

For Oracle-XE:

docker exec -it oraclexe "bash"
...
sqlplus sys as sysdba
...
alter session set "_ORACLE_SCRIPT"=true;
create user oracle identified by admin default tablespace users;
grant dba to oracle;
alter system set processes=1000 scope=spfile;
alter system set sessions=1000 scope=spfile;
ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;
...
quit
...
exit

Manual Database configuration

  • PostgreSQL

    You should install PostgreSQL and the password for the postgres user should be admin.

    Now you need to create a high_performance_java_persistence database.

  • Oracle

    You need to download and install Oracle XE

    Set the sys password to admin

    Connect to Oracle using the "sys as sysdba" user and create a new user:

      alter session set "_ORACLE_SCRIPT"=true;
    
      create user oracle identified by admin default tablespace users;
    
      grant dba to oracle;
    
      alter system set processes=1000 scope=spfile;
    
      alter system set sessions=1000 scope=spfile;
      
      ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;
    

    Open the C:\app\${user.name}\product\21c\homes\OraDB21Home1\network\admin folder where ${user.name} is your current Windows username.

    Locate the tnsnames.ora and listener.ora files and change the port from 1522 to 1521 if that's the case. If you made these modifications, you need to restart the OracleOraDB21Home1TNSListener and OracleServiceXE Windows services.

  • MySQL

    You should install MySQL 8 and the password for the mysql user should be admin.

    Now, you need to create a high_performance_java_persistence schema

    Beside having all privileges on this schema, the mysql user also requires select permission on mysql.PROC.

    If you don't have a mysql user created at database installation time, you can create one as follows:

    CREATE USER 'mysql'@'localhost';
    
    SET PASSWORD for 'mysql'@'localhost'='admin';
    
    GRANT ALL PRIVILEGES ON high_performance_java_persistence.* TO 'mysql'@'localhost';
    
    GRANT SELECT ON mysql.* TO 'mysql'@'localhost';
    
    FLUSH PRIVILEGES;
    
  • SQL Server

    You should install SQL Server Express Edition with Tools. Chose mixed mode authentication and set the sa user password to adm1n.

    Open SQL Server Configuration Manager -> SQL Server Network Configuration and enable Named Pipes and TCP

    In the right pane of the TCP/IP option, choose Properties, then IP Addresses and make sure you Enable all listed IP addresses. You need to blank the dynamic TCP port value and configure the static TCP port 1433 for all IPs.

    Open SQL Server Management Studio and create the high_performance_java_persistence database

Maven

To build the project, don't use install or package. Instead, just compile test classes like this:

mvnw clean test-compile

Or you can just run the build.bat or build.sh scripts which run the above Maven command.

Afterward, just pick one test from the IDE and run it individually.

Don't you run all tests at once (e.g. mvn clean test) because the test suite will take a very long time to complete.

So, run the test you are interested in individually.

Enjoy learning more about Java Persistence, Hibernate, and database systems!

Comments
  • add bidirectional one-to-one cache test

    add bidirectional one-to-one cache test

    Regarding your comment https://vladmihalcea.com/how-does-hibernate-store-second-level-cache-entries/#comment-51251, I created a new test which creates a bidirectional one-to-one relationship and tests loading entities from the 2nd level cache.

    After I made sure all objects are cached, retrieving the object that owns the relationship produced cache hit.

    On the contrary, retrieving the object that is on the inverse side only produces cache hit for that object. After that, a query is issued and the resulting object is put in the cache.

    Or, more specifically, fetching PostDetails produces a cache hit, fetching the child (Post) produces also a cache hit. But, then, populating the child (Post) with its child (PostDetails) hits the database.

    So my conclusion is that hibernate always issues a query to the database when trying to load entity that is on the inverse side of the relationship.

    This query is visible in the log output of the test.

    opened by neno-- 19
  • Compile not working / Oracle JAR requires authorization

    Compile not working / Oracle JAR requires authorization

    When I do

    mvn clean test-compile
    

    There is the error:

    [ERROR] Failed to execute goal on project high-performance-java-persistence: Could not resolve dependencies for project com.vladmihalcea.book:high-performance-java-persistence:pom:1.0-SNAPSHOT: Failed to collect dependencies at com.oracle.jdbc:ojdbc8:jar:12.2.0.1: Failed to read artifact descriptor for com.oracle.jdbc:ojdbc8:jar:12.2.0.1: Could not transfer artifact com.oracle.jdbc:ojdbc8:pom:12.2.0.1 from/to maven.oracle.com (https://maven.oracle.com): Not authorized , ReasonPhrase:Authorization Required. -> [Help 1]
    

    When removing the Oracle dependency compilation works.

    Probably the Oracle JDBC cannot be obtained from Maven central. One solution would be to put the Oracle dependency in a separate Maven profile.

    opened by cruftex 11
  • Error when changing to OneToOne relationship

    Error when changing to OneToOne relationship

    This test works fine with a ManyToOne/OneToMany relationship between PostTag and Tag. However, if that is changed to a OneToOne relationship, the test no longer passes.

    opened by cca-developer 7
  • Getting error java.sql.SQLException: Invalid state, the Statement object is closed

    Getting error java.sql.SQLException: Invalid state, the Statement object is closed

    I have following code.

    public static int execute(String query) throws SQLException {
    Statement stmt = null;
    try {
        stmt = con.createStatement();
        int recordcount = stmt.executeUpdate(query);
        return recordcount;
    } finally {
        stmt.close(); //ERROR getting exception here 
    }
     
    public static Connection getConnection() throws SQLException,ClassNotFoundException {
        con = DbConnectionPool.getDbConnectionPool().getConnection();
        return con;
    }
    

    con is static class variable initialize with the method getConnection() . Exception throws from execute method handle by caller method.

    In most cases, it works fine but in some cases, it will give error "java.sql.SQLException: Invalid state, the Statement object is closed" when I call stmt.close() in finally block. What is the possibility of occurring such error?

    Thank you Salman

    opened by salman-khandu 6
  • UnidirectionalOrderedOneToManyTest failed delete only 1st entry

    UnidirectionalOrderedOneToManyTest failed delete only 1st entry

    Hello,

    The UnidirectionalOrderedOneToManyTest failed for "delete only 1st entry" case The reason is Hibernate generated SQL and as result the integrity constraint violation between //2 and //3 table rows See details in below log. Is it expected? Regards, Alex

    drop table post if exists|
    drop table post_comment if exists|
    drop table post_post_comment if exists|
    drop sequence hibernate_sequence if exists|
    create sequence hibernate_sequence start with 1 increment by 1|
    create table post (id bigint not null, title varchar(255), primary key (id))|
    create table post_comment (id bigint not null, review varchar(255), primary key (id))
    create table post_post_comment (Post_id bigint not null, comments_id bigint not null, entry integer not null, primary key (Post_id, entry))
    alter table post_post_comment add constraint UK_gb03lqukc5jc1u847l17m311q unique (comments_id)
    alter table post_post_comment add constraint FKp3qg7d2x7uh1eiulxe65rhwl2 foreign key (comments_id) references post_comment
    alter table post_post_comment add constraint FKdylii52824tsuhxvxsnancr51 foreign key (Post_id) references post
    insert into post_comment (review, id) values ('My first review', 2)
    insert into post_comment (review, id) values ('My second review', 3)
    insert into post_comment (review, id) values ('My third review', 4)
    insert into post_post_comment (Post_id, entry, comments_id) values (1, 0, 2)//2 - row updated and integrity constraint violation with row 3
    insert into post_post_comment (Post_id, entry, comments_id) values (1, 1, 3)//3
    **insert into post_post_comment (Post_id, entry, comments_id) values (1, 2, 4)//1 - row deleted
    - Remove head
    - Deleted PostComment{id=2, review='My first review'}
    delete from post_post_comment where Post_id=1 and entry=2 //1
    update post_post_comment set comments_id=3 where Post_id=1 and entry=0//2
    SQL Error: -104, SQLState: 23505
    integrity constraint violation: unique constraint or index violation; UK_GB03LQUKC5JC1U847L17M311Q table: POST_POST_COMMENT
    
    opened by senleft 6
  • Fix MySQL command to set password for user, the existing command is not working on MySQL v8

    Fix MySQL command to set password for user, the existing command is not working on MySQL v8

    Dear Vlad,

    I'm taking your High-Performance Java Persistence course. While setting up the workspace with MySQL, I encountered an error in one of the MySQL commands. Raising this Pull Request to get it corrected.

    Regards, Devesh Mankar

    opened by deveshub 5
  • URL link is broken inside Readme.md -MySQL section

    URL link is broken inside Readme.md -MySQL section "here" link in sentense "Exact instructions can be found in here."

    The here link is pointed to https://github.com/ursjoss/high-performance-java-persistence/blob/tb_mysql_instructions/MYSQL.md , which leads to 404 error

    The correct link might be https://github.com/vladmihalcea/high-performance-java-persistence/blob/master/MYSQL.md

    opened by mingqin1 5
  • Improve performance of JsonTypeDescriptor.areEqual

    Improve performance of JsonTypeDescriptor.areEqual

    Hi,

    recently I found that JsonTypeDescriptor.areEqual() checks can be optimized if the objects are already of type String. What do you think of the proposed change?

    Cheers, Christoph

    opened by dreis2211 5
  • The ebook from leanpub.com is impossible to buy from Russia

    The ebook from leanpub.com is impossible to buy from Russia

    This is probably not the best place to describe an issue, but I haven't found a better one.

    The ebook is only available via leanpub.com. This site uses only PayPal to process payments, and it is impossible to pay via PayPal from Russia:

    http://help.leanpub.com/reader-help/im-having-a-problem-using-a-credit-card-from-russian-federation-help

    https://groups.google.com/forum/#!topic/leanpub/EMVVGa9D6C4

    Would you please consider additionally selling an electronic version of the book via another online store? I know that a print version is available on Amazon, but I really do not want to buy the printed one.

    opened by stIncMale 5
  • Set source code encoding to UTF-8

    Set source code encoding to UTF-8

    In case you got this error Error: unmappable character ... for encoding US-ASCII when: mvn clean test-compile

    the only solution I found was to setup the UTF-8 into the /high-performance-java-persistence-master/core/pom.xml like this:

    <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     </properties>
    
    opened by ittrad-mobile-lab 4
  • Oracle schema or MSSQL Schema?

    Oracle schema or MSSQL Schema?

    There's a file in your repository that references both the Oracle and MS SQL dialects: https://github.com/vladmihalcea/high-performance-java-persistence/blob/master/jooq/jooq-mssql/src/test/resources/oracle/initial_schema.sql

    From the contents, I suspect it is MS SQL, as Oracle doesn't have BIGINT or DATETIME2 types... This looks more like Oracle syntax: https://github.com/vladmihalcea/high-performance-java-persistence/blob/master/jooq/jooq-oracle/src/test/resources/oracle/initial_schema.sql

    opened by lukaseder 4
  • Bump postgresql from 42.3.3 to 42.3.8

    Bump postgresql from 42.3.3 to 42.3.8

    Bumps postgresql from 42.3.3 to 42.3.8.

    Changelog

    Sourced from postgresql's changelog.

    Changelog

    Notable changes since version 42.0.0, read the complete History of Changes.

    The format is based on Keep a Changelog.

    [Unreleased]

    Changed

    Added

    Fixed

    [42.5.1] (2022-11-21 15:21:59 -0500)

    Security

    • security: StreamWrapper spills to disk if setText, or setBytea sends very large Strings or arrays to the server. createTempFile creates a file which can be read by other users on unix like systems (Not macos). This has been fixed in this version fixes CVE-2022-41946 see the security advisory for more details. Reported by Jonathan Leitschuh This has been fixed in versions 42.5.1, 42.4.3 42.3.8, 42.2.27.jre7. Note there is no fix for 42.2.26.jre6. See the security advisory for work arounds.

    Fixed

    [42.5.0] (2022-08-23 11:20:11 -0400)

    Changed

    [42.4.2] (2022-08-17 10:33:40 -0400)

    Changed

    • fix: add alias to the generated getUDT() query for clarity (PR #2553)[https://github-redirect.dependabot.com/pgjdbc/pgjdbc/pull/2553]

    Added

    Fixed

    • fix: regression with GSS. Changes introduced to support building with Java 17 caused failures [Issue #2588](pgjdbc/pgjdbc#2588)
    • fix: set a timeout to get the return from requesting SSL upgrade. [PR #2572](pgjdbc/pgjdbc#2572)
    • feat: synchronize statement executions (e.g. avoid deadlock when Connection.isValid is executed from concurrent threads)

    [42.4.1] (2022-08-01 16:24:20 -0400)

    Security

    • fix: CVE-2022-31197 Fixes SQL generated in PgResultSet.refresh() to escape column identifiers so as to prevent SQL injection.
      • Previously, the column names for both key and data columns in the table were copied as-is into the generated SQL. This allowed a malicious table with column names that include statement terminator to be parsed and executed as multiple separate commands.
      • Also adds a new test class ResultSetRefreshTest to verify this change.
      • Reported by Sho Kato

    ... (truncated)

    Commits
    • e73c6b6 backpatch changes to 42.3.x for 42.5.1 (#2674)
    • 3ea7e61 bumped version for next release
    • 0afaa71 backpatch changes from GHSA-r38f-c4h4-hqq2 security advisory for CVE-2022-311...
    • 7714d03 Created release notes for 42.3.6 [SKIP-CI] (#2515)
    • 85f8581 fix: close refcursors when underlying cursor==null instead of relying on defa...
    • 12541c4 bumped version number
    • 0872ad0 Fix heading format for version numbers (#2504)
    • 0d6ccb1 More changlog additions added chore to terminate CI jobs on fast PR pushes [S...
    • 2bd774e Releasenotes 42.3.5 (#2502)
    • c04582e chore: use GitHub Action concurrency feature to terminate CI jobs on fast PR ...
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Bump hsqldb from 2.4.0 to 2.7.1

    Bump hsqldb from 2.4.0 to 2.7.1

    Bumps hsqldb from 2.4.0 to 2.7.1.

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Bump jackson-databind from 2.12.6.1 to 2.12.7.1

    Bump jackson-databind from 2.12.6.1 to 2.12.7.1

    Bumps jackson-databind from 2.12.6.1 to 2.12.7.1.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Add tests for inherited entity reference equality

    Add tests for inherited entity reference equality

    Hi, Vlad. I wrote some tests for equality when we have inheritance.


    Test class - InheritedEntityReferenceEqualityTest

    Test method - testInheritedEntityReferenceEqualityInOnTransaction

    When we try to persist entity in one transaction and after it use getReference everything works as expected.

    Test method - testInheritedEntityReferenceEqualityInDifferentTransactions

    In this test case we separate entity persist from getReference, and after it the instanceof or o.getClass() check for inherited entity does`t work.


    Example: postProxy.hashCode() == post.hashCode(); // = true postProxy.getClass() == post.getClass(); // = false postProxy instanceof Post // = false post instanceof Post // = true postProxy.equals(post); // = true post.equals(postProxy); // = false


    Possible solutions to resolve this problem: use Hibernate.getClass(o) instead of !(o instanceof Topic) or getClass() != o.getClass() in equals method.

    opened by ivan909020 1
  • Add tests for delete parent entity with @OneToMany cascade = ALL

    Add tests for delete parent entity with @OneToMany cascade = ALL

    Hi, Vlad. I wrote some tests with delete operation after tricky select.


    Test class - DeletingAfterFetchWithoutSQLCascadeTest

    Test method - testDeleteParentAfterEagerInnerFetchInChildWithoutSQLCascadeInOneTransaction

    When we try to delete parent entity (Audience) after select with join fetch with list of Lesson and inside them also join list of Group (groups also have lessons, and they have EAGER fetch mapping). The ConstraintViolationException will occur after parent (Audience) delete. Even if we try to delete child entities (Lesson) explicitly before parent delete (Audience), anyway the same exception will occur.

    Test method - testDeleteParentAfterEagerInnerFetchInChildWithoutSQLCascadeThenSaveAnotherEntityInDifferentTransactions

    In this test case we have the same logic, but do all operations in different transactions.


    Test class - DeletingAfterFetchWithSQLCascadeTest

    Test method - testDeleteParentAfterEagerInnerFetchInChildWithSQLCascadeInOneTransaction

    In this test case we have similar logic, but the database lesson table doesn't have ON DELETE CASCADE constraint. And we have another exception - TransientPropertyValueException.

    Test method - testDeleteParentAfterEagerInnerFetchInChildWithSQLCascadeThenSaveAnotherEntityInDifferentTransactions

    In this test case we have the same logic, but if we do all operations in different transactions. And the TransientPropertyValueException will occur not after parent (Audience) delete, but in the next operation, for example - merge different Audience that doesn't belong to the main select with join fetch.


    Possible solutions to resolve this problem: set fetch = FetchType.LAZY for lessons in Group OR @OnDelete(action = OnDeleteAction.CASCADE) instead of cascade = CascadeType.ALL OR entityManager.clear(); before delete Audience OR add sql cascades and @GeneratedValue(strategy = GenerationType.SEQUENCE)


    Just for examination, spring data jpa issue: https://github.com/spring-projects/spring-data-jpa/issues/2281

    opened by ivan909020 1
Owner
Vlad Mihalcea
Java Champion, developing Hypersistence Optimizer, and author of High-Performance Java Persistence.
Vlad Mihalcea
100+ Spring Boot Articles, Tutorials, Video tutorials, Projects, Guides, Source code examples etc

YouTube Channel - Spring Boot Tutorial Subscribe for future video and updates Spring Boot Tutorial on YouTube Newly published spring boot tutorials (2

Ramesh Fadatare 1.2k Jan 2, 2023
This repository contains source code examples to support my course Spring Data JPA and Hibernate Beginner to Guru

Spring Data JPA - Spring Data JPA This repository contains source code examples to support my course Spring Data JPA and Hibernate Beginner to Guru Co

John Thompson 8 Aug 24, 2022
📺 Streaming OBS video/Mjpeg into maps on item frames at a high frame rate

MakiScreen Mjpeg ?? Streaming OBS video/Mjpeg into maps on item frames at a high frame rate images taken on TotalFreedom: play.totalfreedom.me How doe

null 4 Apr 8, 2022
Source codes of book Java Concurrency In Practice, rebuild by maven.

Introduction Source codes of book: Java Concurrency In Practice(2011, Brain Goetz etc. jcip for short.), rebuild from https://jcip.net/ with maven. Mo

Sam Sune 2 Jun 9, 2022
A Minecraft Fabric mod to make crafting with the recipe book faster

OneClickCrafting This mod is clientside only. After selecting a recipe in the recipe book, the client with shift-click the crafted item from the resul

BreadMoirai 4 Jun 2, 2022
ActiveJ is an alternative Java platform built from the ground up. ActiveJ redefines web, high load, and cloud programming in Java, featuring ultimate performance and scalability!

Introduction ActiveJ is a full-featured modern Java platform, created from the ground up as an alternative to Spring/Micronauts/Netty/Jetty. It is des

ActiveJ LLC 579 Jan 7, 2023
Java Design Patterns code examples

Java Design Patterns code examples Behavioral In software engineering, behavioral design patterns are design patterns that identify common communicati

Gaboso™ 3 Jun 29, 2022
This Web Application Allows A user to upload a two minutes Video. It uses Server Side Capabilities of Nodejs and Spring Boot .

VideoStreamingApplication Purpose Of This Application These days trend of short videos are on rise youtube recently realsed "Shorts" . So , taking ins

Prateek Kumar 57 Nov 13, 2022
Presti 5 Nov 19, 2022
The lightweight library for compress image, video, and audio with an awesome experience

Would you like to support me? react-native-compressor Compress videos, images and audio before upload react-native-compressor package is a set of func

Shobbak 265 Jan 1, 2023
Log4j CVE-2021-44228 examples: Remote Code Execution (through LDAP, RMI, ...), Forced DNS queries, ...

Log4j CVE-2021-44228 and CVE-2021-45046 Requisites Use a vulnerable JDK, for instance JDK 1.8.0_181 Usage Malicious server The malicious server deploy

Manuel Álvarez Álvarez 5 Feb 7, 2022
High Performance data structures and utility methods for Java

Agrona Agrona provides a library of data structures and utility methods that are a common need when building high-performance applications in Java. Ma

Real Logic 2.5k Jan 7, 2023
Live video out from your DJI FPV Goggles via USB.

DigiView is an Android app that allows you to get a live preview from your DJI FPV Goggles (V1 & V2). Working with Android 7+ and devices supporting U

Fpv Out Club 235 Dec 19, 2022
bilibili B站 哔哩哔哩 acfun A站 樱花动漫 番剧下载器(Video Downloader):smiley:​ 仅供学习交流 求 star orz

AnimeDownloader 番剧下载器 ?? 使用教程 下载 B 站视频 支持的类型 普通视频(不支持互动类视频) 番剧(大会员视频需要先登录) 电影 纪录片 ... 下载 A 站视频 支持类型 普通视频 番剧(不支持付费视频) 下载樱花动漫视频 支持类型 部分支持(加密的 m3u8 类型视频不

lin 71 Dec 16, 2022
Record 360 video with jMonkeyEngine3

jm3-360-video Record 360 video with jMonkeyEngine3 Check CustomVideoRecorderAppStateTest.java for usage. Example: https://youtu.be/TccLGPPZ3Iw This wi

Rickard Edén 3 Jan 24, 2022
Google's ML-Kit-Vision demo (android) for pre encoded video.

Android ML Kit Vision demo with Video Google's ML-Kit-Vision demo (android) for pre encoded video. Demos for camera preview and still image are also i

null 17 Dec 29, 2022
Clivia is a scalable, high-performance, elastic and responsive API gateway based on spring weblux

clivia是一款基于spring webflux的可扩展、高性能、高弹性、响应式的 API 网关 clivia_V0.0.1 架构概览 模块介绍 clivia-admin-core : 网关配置管理后台核心模块 clivia-client-core : 网关核心模块 clivia-example

palading 14 Jan 9, 2023
✈A high-performance RPC based on Java & Netty.

bRPC README 中文版本 一个基于netty的RPC框架 基于netty NIO、IO多路复用。 client与server端建立心跳包保活机制。发生未知断连时,重连保证可靠长连接。 使用kryo序列化,自定义传输包,及传输格式,避免TCP沾包问题。 支持zookeeper或nacos做服务

vincent 238 Dec 16, 2022
ShenYu is High-Performance Java API Gateway.

Scalable, High Performance, Responsive API Gateway Solution for all MicroServices https://shenyu.apache.org/ English | 简体中文 Architecture Features Shen

The Apache Software Foundation 7.5k Jan 4, 2023