Giter Site home page Giter Site logo

anghelleonard / hibernate-springboot Goto Github PK

View Code? Open in Web Editor NEW
1.3K 86.0 531.0 32.59 MB

Collection of 300+ best practices for Java persistence performance in Spring Boot applications

Home Page: https://www.amazon.com/Spring-Boot-Persistence-Best-Practices/dp/1484256255/ref=sr_1_3?keywords=anghel+leonard&qid=1576272956&sr=8-3

License: Apache License 2.0

Java 99.72% HTML 0.28%
java hibernate hibernate-jpa springboot persistence spring-data jpa jdbc sql functions

hibernate-springboot's People

Contributors

anghelleonard avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hibernate-springboot's Issues

duplicate records fetched while using findall method with specification and payable

I'm seeing some weird issue while working with findAll() method with the specification and pageable arguments. If I set the lower page i.e. 0 size i.e. 10 then I don't have any issues. but if I set the page i.e. 0 and size to 30 I'm getting the duplicate records.

e.g.

ID NAME
1 test
2 test
3 test
4 test
5 test
6 test
7 test
8 test
9 test
1 test
2 test
3 test
4 test
11 test
6 test
7 test
18 test

I have the following in the database.

ID NAME
1 test
2 test
3 test
4 test
5 test
6 test
7 test
8 test
9 test
10 test
11 test
12 test
13 test
14 test
15 test
16 test
17 test
18 test

@Entity
@Table(name = "table_name")
@JsonIgnoreProperties(ignoreUnknown = true)
@DynamicUpdate
public class Emp implements Persistable<String> {

    @Id
    @Column(name = "emp_id", nullable = false, columnDefinition = "BINARY(16)")
    public String empId;
    
    @Column(name = "name");
    public String name;
    // other fields
    
    //setters and getters
    
}
@Repository
public interface EmpRepository extends JpaRepository<Emp, String> {
    Page<Emp> findAll(Specification<Emp> specification, Pageable page);
}
public class EmpSpecification {
    public static Specification<Emp> nameEquals(String name) {
        return (root, query, builder) -> name == null ? null : builder.equal(root.get("name"), name);
    }
}

in the service class we are trying to fetch data using the following code:

Specification<Emp> specifications = Specification.where(EmpSpecification.nameEquals(name)));
details = consolidatedTradeSummaryRepository.findAll(specifications, page);

http://localhost:8080/emp?name=test&page=0&size=10
http://localhost:8080/emp?name=test&page=0&size=20

Spring boot version : 2.2.2.RELEASE

HibernateSpringBootLeftJoinFetch/README.md error

Similar, we can fetch all Book, including those with no registered Author. This can be done via JOIN FETCH or **JOIN**.
JOIN didn't return all Book. The result excluding the record when the author_id is null.

HibernateSpringBootOneToManyBidirectional has issue with removeBooks method

Hi,

Thanks for awesome book.

HibernateSpringBootOneToManyBidirectional has helper method removeBooks.

    @Transactional
    public void deleteAllBooksOfAuthor() {
        Author author = authorRepository.findByName("Joana Nimar");
        author.removeBooks(); // use removeBooks() helper    
    }

But if you see carefully, it calls delete for each book entity. Can we optimize it somehow to call like IN queries instead?

Also purpose of these helper methods is to call on managed entities or detached ones only?

Extra queries on @OneToOne relation with lazy fetch type

I tried the example with the hibernate-enhance-maven-plugin activated, and confirmed that direct @OnetoOne relations were being lazily loaded. I created a Book class with a @OnetoOne to Author, and every time I fetched a book, the author was being fetched lazily:

select book0_.id as id1_1_0_, book0_.author as author2_1_0_ from book book0_ where book0_.id=?

However, when I fetch an Author, which has an inverse @OnetoOne relation with Book, an extra query is being excecuted:

select author0_.id as id1_0_0_, author0_.age as age2_0_0_, author0_.avatar as avatar3_0_0_, author0_.genre as genre4_0_0_, author0_.name as name5_0_0_ from author author0_ where author0_.id=?
select book0_.id as id1_1_0_, book0_.author as author2_1_0_ from book book0_ where book0_.author=?  // <-- This shouldn't be fetched

I read that this happens because hibernate does not know if it has to create a proxy or load it with a null reference, but I thought that the enhancement plugin fixed this.

This is the book class I created:

@Entity
public class Book implements Serializable {
    private static final long serialVersionUID = 2L;

    @Id
    public Long id;

    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "author")
    public Author author;
}

and the author class is the same as in the example, but I added the inverse relation:

@OneToOne(mappedBy = "author", fetch = FetchType.LAZY)
Book book;

Is there an error in my tests or it's still a limitation in the library? How are we suposed to solve this problem? Since if I fetch a list of objects with inverse relations, I will be making several extra queries and it will negatively impact on the performance

Forgot to mention: I also tried using @LazyToOne and @LazyGroup annotations in each field, but had the same results.

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.