Giter Site home page Giter Site logo

in28minutes / jpa-with-hibernate Goto Github PK

View Code? Open in Web Editor NEW
617.0 53.0 763.0 613 KB

Master JPA using Hibernate as the implementation. Learn the basics of JPA - entities, relationships, entity manager, annotations, JPQL and Criteria API. Take a step into the advanced world of JPA - caching, performance tuning(n + 1 queries), mapping inheritance hierarchies. Get a peek into the magic of Spring Data JPA & Spring Data Rest.

Java 100.00%

jpa-with-hibernate's People

Contributors

bsmahi avatar in28minutes 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

jpa-with-hibernate's Issues

findByID JPA not working

package com.ayush.jpa.JpaDemo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class JpaDemoApplication implements CommandLineRunner {

private Logger logger = LoggerFactory.getLogger(JpaDemoApplication.class);

@Autowired
private PersonRepository repo;

public static void main(String[] args) {
	SpringApplication.run(JpaDemoApplication.class, args);
}

@Override
public void run(String... args) throws Exception {
	// TODO Auto-generated method stub

	logger.info("Person findById----", repo.findById(10002));

}

}

package com.ayush.jpa.JpaDemo;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@entity
public class Person {

@Id
@GeneratedValue
private int id;

private String name;
private String location;
private Date birthDate;

public Person() {

}

public Person(int id, String name, String location, Date birthDate) {
	super();
	this.id = id;
	this.name = name;
	this.location = location;
	this.birthDate = birthDate;
}

public Person(String name, String location, Date birthDate) {
	super();
	this.name = name;
	this.location = location;
	this.birthDate = birthDate;
}

public int getId() {
	return id;
}

public void setId(int id) {
	this.id = id;
}

public String getName() {
	return name;
}

public void setName(String name) {
	this.name = name;
}

public String getLocation() {
	return location;
}

public void setLocation(String location) {
	this.location = location;
}

public Date getBirthDate() {
	return birthDate;
}

public void setBirthDate(Date birthDate) {
	this.birthDate = birthDate;
}

@Override
public String toString() {
	return String.format("\nPerson [id=%s, name=%s, location=%s, birthDate=%s]", id, name, location, birthDate);
}

}

package com.ayush.jpa.JpaDemo;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.transaction.Transactional;

import org.springframework.stereotype.Repository;

@repository
@transactional
public class PersonRepository {

@PersistenceContext
EntityManager manager;

public Person findById(int id) {
	return manager.find(Person.class, id);
}

}

EntityManager.detach method is not working when testing using JUnit

Hello Ranga,

I am learning the course associated with this repo and I am at the Step#12 of Chapter#5, which is to play with the entitymanager.

This is the target method in my CourseRepository class:

public Long checkDetach() {
        Course course = new Course("HAPPY PYTHON");
        em.persist(course);
        em.flush();
        em.detach(course);
        course.setName("HAPPY MORE PYTHON");
        return course.getId();
    }

And this is the test method I wrote for the above method:

    @Test
    @DirtiesContext
    public void testCheckDetach() {
        // Case will fail in unit testing.
        Long newId = courseRepository.checkPersistence();
        Course course = courseRepository.findById(newId);
        assertEquals("HAPPY PYTHON", course.getName());
    }

The above test case will not pass as the target course entity is still updated even after it was detached.

However, if running the application directly with the below method defined in the run method as follows:

	@Override
	public void run(String... args) throws Exception {
		courseRepository.checkDetach();
	}

This will correctly reflect what the checkDetach() specifies, which will successfully detach the target course entity and will not update the associated entry in the h2 database.

So I am quite confused and wondering what I missed to create a correct unit test case for the checkDetach method and I would really appreciate if you could provide some suggestions on that.

Error: At least one JPA metamodel must be present!

Getting the following error while creating new maven project with dependencies jdbc, jpa, h2 and web using spring initializer,
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: At least one JPA metamodel must be present!

Course agenda update 20240215

Dear Ranga, classmates and friends:

Here my transcription ordered for the Course Agenda, I hope you will like and having useful:

  1. Journey from JDBC To JPA Step01 - Setting up a project with JDBC, JPA, H2 and Web Dependencies
  2. seccion 1: Introduction 01. Master Hibernate and JPA with Spring Boot - Preview
  3. seccion 1: Introduction 02. Congratulations
  4. seccion 1: Introduction 03. One thing you should do
  5. seccion 1: Introduction 04. Master Hibernate and JPA with Spring Boot - Course Overview
  6. seccion 1: Introduction 05. Master Hibernate and JPA with Spring Boot - Git Repository
  7. seccion 1: Introduction 06. Master Hibernate and JPA with Spring Boot - Installing Basic Tools
  8. seccion 1: Introduction 07. Quick introduction to JPA
  9. seccion 1: Introduction 08. DO NOT SKIP: Join in28minutes learning community
  10. sección 2: Introduction to Spring Boot in 10 steps 09. Do not skip. New to Spring framework?
  11. sección 2: Introduction to Spring Boot in 10 steps 10. Step 01 - Getting Started with Spring Boot - Goals?
  12. sección 2: Introduction to Spring Boot in 10 steps 11. Step 02 - Setting up New Spring Boot Project with Spring?
  13. sección 2: Introduction to Spring Boot in 10 steps 12. Step 03 - Setting up New Spring Boot Project with Spring?
  14. sección 2: Introduction to Spring Boot in 10 steps 13. Step 04 - Build a Hello World with API with Spring Boot
  15. sección 2: Introduction to Spring Boot in 10 steps 14. Step 05 - Understanding the goal of Spring Boot
  16. sección 2: Introduction to Spring Boot in 10 steps 15. Step 06 - Understanding the Spring Boot Magic - Spring Boot Starter
  17. sección 2: Introduction to Spring Boot in 10 steps 16. Step 07 - Understanding the Spring Boot Magic - Auto Configuration
  18. sección 2: Introduction to Spring Boot in 10 steps 17. Step 08 - Build Faster with Spring Boot DevTools
  19. sección 2: Introduction to Spring Boot in 10 steps 18. Step 09 - Get Production ready with Spring Boot 1 Profiles
  20. sección 2: Introduction to Spring Boot in 10 steps 19. Step 10 - Get Production ready with Spring Boot 2 Configuration Properties
  21. sección 2: Introduction to Spring Boot in 10 steps 20. Step 11 - Get Production ready with Spring Boot DevTools 3 Embedded Servers
  22. sección 2: Introduction to Spring Boot in 10 steps 21. Step 12 - Get Production ready with Spring Boot DevTools 4 Actuator
  23. sección 2: Introduction to Spring Boot in 10 steps 22. Step 13 - Understanding Spring Boot vs Spring vs Spring MVC
  24. sección 2: Introduction to Spring Boot in 10 steps 23. Step 14 - Getting started with Spring Boot - Review
  25. Journey from JDBC To JPA 24. introduction to Journey from JDBC To JPA
  26. Journey from JDBC To JPA 25. Step01 - Setting up a project with JDBC, JPA, H2 and Web Dependencies
  27. Journey from JDBC To JPA 26. COURSE UPDATE: H2 Database URL
  28. Journey from JDBC To JPA 27. Step02 - Launching up H2 Console
  29. Journey from JDBC To JPA 28. Troubleshooting Your Problems
  30. Journey from JDBC To JPA 29. Step03 - Creating a Database Table in H2
  31. Journey from JDBC To JPA 30. Step04 - Populate data into Person Table
  32. Journey from JDBC To JPA 31. Step05 - Implement findAll persons Spring JDBC Query Method
  33. Journey from JDBC To JPA 32. Step06 - Execute the findAll method using CommandLineRunner
  34. Journey from JDBC To JPA 33. Step07 - A Quick Review - JDBC vs Spring JDBC
  35. Journey from JDBC To JPA 34. Step08 - Whats in the background? Understanding Spring Boot Autoconfiguration
  36. Journey from JDBC To JPA 35. Step09 - Implementing findById Spring JDBC Query Method
  37. Journey from JDBC To JPA 36. Step10 - Implementing deleteById Spring JDBC Update Method
  38. Journey from JDBC To JPA 37. Step11 - Implementing insert and update Spring JDBC Update Methods
  39. Journey from JDBC To JPA 38. Step12 - Creating a custom Spring JDBC RowMapper
  40. Journey from JDBC To JPA 39. Step13 - Quick introduction to JPA
  41. Journey from JDBC To JPA 40. Step14 - Defining Person Entity
  42. Journey from JDBC To JPA 41. Step15 - Implementing findById JPA Repository Method
  43. Journey from JDBC To JPA 42. Step16 - Implementing insert and update JPA Repository Methods
  44. Journey from JDBC To JPA 43. Step17 - Implementing deleteById JPA Repository Method
  45. Journey from JDBC To JPA 44. Step18 - Implementing findAll using JPQL Named Query
  46. Sección 4: Introduction to JUnit in 5 Steps 45. Introduction to JUnit in 5 Steps
  47. Sección 4: Introduction to JUnit in 5 Steps 46. Step 01: What is Junit and Unit Testing?
  48. Sección 4: Introduction to JUnit in 5 Steps 47. Step 02: Your First Junit Project and Green Bar
  49. Sección 4: Introduction to JUnit in 5 Steps 48. Step 03: Your First Junit Code and First Unit Test
  50. Sección 4: Introduction to JUnit in 5 Steps 49. Step 04: Exploring other assert methods
  51. Sección 4: Introduction to JUnit in 5 Steps 50. Step 05: Exploring few important Junit annotations
  52. Sección 5: JPA/Hibernate in Depth 51. Introduction to JPA and Hibernate in Depth
  53. Sección 5: JPA/Hibernate in Depth 52. Step01 - Create a JPA Project with H2 and Spring Boot
  54. Sección 5: JPA/Hibernate in Depth 53. COURSE UPDATE: H2 Database URL
  55. Sección 5: JPA/Hibernate in Depth 54. Step02 - Create JPA Entity Course
  56. Sección 5: JPA/Hibernate in Depth 55. Step03 - Create findById using JPA Entity Manager
  57. Sección 5: JPA/Hibernate in Depth 56. Step04 - Configuring application.properties to enable H2 console and additional logging
  58. Sección 5: JPA/Hibernate in Depth 57. COURSE UPDATE : JUnit 4 vs JUnit 5
  59. Sección 5: JPA/Hibernate in Depth 58. Step05 - Writing Unit Test for findById method
  60. Sección 5: JPA/Hibernate in Depth 59. Step06 - Writing a deleteByID method to delete an Entity
  61. Sección 5: JPA/Hibernate in Depth 60. Step07 - Writing Unit Test for deleteById method
  62. Sección 5: JPA/Hibernate in Depth 61. Step08 - Writing a save method to update and insert an Entity
  63. Sección 5: JPA/Hibernate in Depth 62. Step09 - Writing Unit Test for save method
  64. Sección 5: JPA/Hibernate in Depth 63. Step10 - Quick Review and Debugging Tips
  65. Sección 5: JPA/Hibernate in Depth 64. Step11 - Playing with Entity Manager
  66. Sección 5: JPA/Hibernate in Depth 65. Step12 - Entity Manager Methods - clear and detach
  67. Sección 5: JPA/Hibernate in Depth 66. Step13 - Entity Manager Methods - refresh
  68. Sección 5: JPA/Hibernate in Depth 67. Step14 - A Quick Review of Entity Manager
  69. Sección 5: JPA/Hibernate in Depth 68. Step15 - JPQL - Basics
  70. Sección 5: JPA/Hibernate in Depth 69. Step16 - JPA and Hibernate Annotations - @table
  71. Sección 5: JPA/Hibernate in Depth 70. Step17 - JPA and Hibernate Annotations - @column
  72. Sección 5: JPA/Hibernate in Depth 71. Step18 - JPA and Hibernate Annotations - @UpdateTimestamp and @CreationTimestamp
  73. Sección 5: JPA/Hibernate in Depth 72. Step19 - JPA and Hibernate Annotations - @NamedQuery and @NamedQueries
  74. Sección 5: JPA/Hibernate in Depth 73. Step20 - Native Queries - Basics
  75. Sección 6: Establishing Relationsships with JPA and Hibernate - OneToOne 74. Step21 - Entities and Relationships - An overview
  76. Sección 6: Establishing Relationsships with JPA and Hibernate - OneToOne 75. Step22 - Defining Entities - Student, Passport and Review
  77. Sección 6: Establishing Relationsships with JPA and Hibernate - OneToOne 76. Step23 - Introduction to One to One Relationship
  78. Sección 6: Establishing Relationsships with JPA and Hibernate - OneToOne 77. Step24 - OneToOne Mapping - Insert Student with Passport
  79. Sección 6: Establishing Relationsships with JPA and Hibernate - OneToOne 78. Step25 - OneToOne Mapping - Retrieving Student with Passport and Eager Fetch
  80. Sección 6: Establishing Relationsships with JPA and Hibernate - OneToOne 79. Step26 - OneToOne Mapping - Lazy Fetch
  81. Sección 6: Establishing Relationsships with JPA and Hibernate - OneToOne 80. Step27 - Session vs Transaction
  82. Sección 6: Establishing Relationsships with JPA and Hibernate - OneToOne 81. Step28 - OneToOne Mapping - Bidirectional Relationship - Part 1
  83. Sección 6: Establishing Relationsships with JPA and Hibernate - OneToOne 82. Step29 - OneToOne Mapping - Bidirectional Relationship - Part 2
  84. Sección 7. Lets' review with a fes FAQs about Hibernate and JPA 83. FAQ 1 - When does Hibernate send updates to the database?
  85. Sección 7. Lets' review with a fes FAQs about Hibernate and JPA 84. FAQ 2 - When do we need @transactional in an Unit Test?
  86. Sección 7. Lets' review with a fes FAQs about Hibernate and JPA 85. FAQ 3 - Do read only methods need a transaction?
  87. Sección 7. Lets' review with a fes FAQs about Hibernate and JPA 86. FAQ 4 - Why do we use @DirtiesContext in an Unit Test?
  88. Sección 8: Establishing Relationships with JPA and Hibernate - OneToMany and ManyToMany 87. Step30 - ManyToOne Mapping - Designing the database
  89. Sección 8: Establishing Relationships with JPA and Hibernate - OneToMany and ManyToMany 88. Step30 - Part 2 - ManyToOne Mapping - Implementing the Mapping
  90. Sección 8: Establishing Relationships with JPA and Hibernate - OneToMany and ManyToMany 89. Step31 - ManyToOne Mapping - Retrieving and inserting Reviews for Course
  91. Sección 8: Establishing Relationships with JPA and Hibernate - OneToMany and ManyToMany 89. Step31 - ManyToOne Mapping - Retrieving and inserting Reviews for Course
  92. Sección 8: Establishing Relationships with JPA and Hibernate - OneToMany and ManyToMany 90. Step32 - ManyToOne Mapping - Generalizing Insert Reviews
  93. Sección 8: Establishing Relationships with JPA and Hibernate - OneToMany and ManyToMany 91. Step33 - ManyToOne Mapping - Wrapping up
  94. Sección 8: Establishing Relationships with JPA and Hibernate - OneToMany and ManyToMany 92. Step34 - ManyToMany Mapping - Table Design
  95. Sección 8: Establishing Relationships with JPA and Hibernate - OneToMany and ManyToMany 93. Step35 - ManyToMany Mapping - Adding Annotations on Entities
  96. Sección 8: Establishing Relationships with JPA and Hibernate - OneToMany and ManyToMany 94. Step36 - ManyToMany Mapping - Fixing two join tables problem
  97. Sección 8: Establishing Relationships with JPA and Hibernate - OneToMany and ManyToMany 95. Step37 - ManyToMany Mapping - Customizing the Join Table
  98. Sección 8: Establishing Relationships with JPA and Hibernate - OneToMany and ManyToMany 96. Step38 - ManyToMany Mapping - Insert Data and Write Join Query
  99. Sección 8: Establishing Relationships with JPA and Hibernate - OneToMany and ManyToMany 97. Step39 - ManyToMany Mapping - Retrieve Data using JPA Relationships
  100. Sección 8: Establishing Relationships with JPA and Hibernate - OneToMany and ManyToMany 98. Step40 - ManyToMany Mapping - Insert Student and Course
  101. Sección 8: Establishing Relationships with JPA and Hibernate - OneToMany and ManyToMany 99. Step41 - Relationships between JPA Entities - A summary
  102. Sección 9: Inheritance Hierachies with JPA and Hibernate 100. Step42 - Introduction to Inheritance Hierarchies and Mappings
  103. Sección 9: Inheritance Hierachies with JPA and Hibernate 101. Step43 - JPA Inheritance Hierarchies and Mappings - Setting up entities
  104. Sección 9: Inheritance Hierachies with JPA and Hibernate 102. Step44 - JPA Inheritance Hierarchies and Mappings - Setting up a Repository
  105. Sección 9: Inheritance Hierachies with JPA and Hibernate 103. Step45 - JPA Inheritance Hierarchies and Mappings - Single Table
  106. Sección 9: Inheritance Hierachies with JPA and Hibernate 104. Step46 - JPA Inheritance Hierarchies and Mappings - Table Per Class
  107. Sección 9: Inheritance Hierachies with JPA and Hibernate 105. Step47 - JPA Inheritance Hierarchies and Mappings - Joined
  108. Sección 9: Inheritance Hierachies with JPA and Hibernate 106. Step48 - JPA Inheritance Hierarchies and Mappings - Mapped Super Class
  109. Sección 9: Inheritance Hierachies with JPA and Hibernate 107. Step49 - JPA Inheritance Hierarchies and Mappings - How to Choose?
  110. Sección 10: Queries with Entities using JPQL 108. Step50 - JPQL - Courses without Students
  111. Sección 10: Queries with Entities using JPQL 109. Step51 - JPQL - Courses with atleast 2 Students and order by
  112. Sección 10: Queries with Entities using JPQL 110. Step52 - JPQL - Courses like 100 Steps
  113. Sección 10: Queries with Entities using JPQL 111. Step53 - JPQL - Using Joins
  114. Sección 11: Queries using Java API - Criteria Queries 112. Step54 - Criteria Query - Retrieving all courses
  115. Sección 11: Queries using Java API - Criteria Queries 113. Step55 - Criteria Query - Courses like 100 Steps
  116. Sección 11: Queries using Java API - Criteria Queries 114. Step56 - Criteria Query - Courses without Students
  117. Sección 11: Queries using Java API - Criteria Queries 115. Step57 - Criteria Query - Using Joins
  118. Sección 12: Transaction Management 116. Step58 - Introduction to Transaction Management
  119. Sección 12: Transaction Management 117. Step59 - Transaction Management - ACID Properties
  120. Sección 12: Transaction Management 118. Step60 - Understanding Dirty, Phanthom and Non Repeatable Reads
  121. Sección 12: Transaction Management 119. Step61 - Understand 4 Isolation Levels
  122. Sección 12: Transaction Management 120. Step62 - Choosing between Isolation Levels
  123. Sección 12: Transaction Management 121. Step63 - Implementing Transaction Management - 3 Things to Decide
  124. Sección 13: Spring Data JPA & Spring Data REST 122. Step64 - Introduction to Spring Data JPA
  125. Sección 13: Spring Data JPA & Spring Data REST 123. Step65 - Testing the Spring Data JPA Repository with findById.
  126. Sección 13: Spring Data JPA & Spring Data REST 124. Step66 - Spring Data JPA Repository - CRUD Methosd
  127. Sección 13: Spring Data JPA & Spring Data REST 125. Step67 - Sorting using Spring Data JPA Repository
  128. Sección 13: Spring Data JPA & Spring Data REST 126. Step68 - Pagination using Spring Data JPA Repository
  129. Sección 13: Spring Data JPA & Spring Data REST 127. Step69 - Custom Queries using Spring Data JPA Repository
  130. Sección 13: Spring Data JPA & Spring Data REST 128. Step70 - Spring Data REST
  131. Sección 14: Caching with Hibertate & JPA 129. Step71 - Introduction to Caching
  132. Sección 14: Caching with Hibertate & JPA 130. Step72 - Hibernate and JPA Caching - First Level Cache
  133. Sección 14: Caching with Hibertate & JPA 131. Step73 - Hibernate and JPA Caching - Basics of Second Level Cache with EhCache
  134. Sección 14: Caching with Hibertate & JPA 132. Step74 - Hibernate and JPA Caching - Second Level Cache Part 2
  135. Sección 15: Hibernate & JPA Tips 133. Step75 - Hibernate Tips - Hibernate Soft Deletes - @SQLDelete and @where
  136. Sección 15: Hibernate & JPA Tips 134. Step76 - Hibernate Soft Deletes - Part 2
  137. Sección 15: Hibernate & JPA Tips 135. Step77 - JPA Entity Life Cycle Methods
  138. Sección 15: Hibernate & JPA Tips 136. Step78 - Using Embedded and Embeddable with JPA
  139. Sección 15: Hibernate & JPA Tips 137. Step79 - Using Enums with JPA
  140. Sección 15: Hibernate & JPA Tips 138. Step80 - JPA Tip - Be cautious with toString method implementations
  141. Sección 15: Hibernate & JPA Tips 139. Step81 - JPA Tip - When do you use JPA?
  142. Sección 16: Performance Tuning Tips with Hibernate & JPA 140. Step82 - Performance Tuning - Measure before Tuning
  143. Sección 16: Performance Tuning Tips with Hibernate & JPA 141. Step83 - Performance Tuning - Indexes
  144. Sección 16: Performance Tuning Tips with Hibernate & JPA 142. Step84 - Performance Tuning - Use Appropriate Caching
  145. Sección 16: Performance Tuning Tips with Hibernate & JPA 143. Step85 - Performance Tuning - Eager vs Lazy Fetch
  146. Sección 16: Performance Tuning Tips with Hibernate & JPA 144. Step86 - Performance Tuning - Avoid N+1 Problems
  147. Sección 17: Few more FAQ 145. FAQ 5 - How to connect to a differente database sith Spring Boot
  148. Sección 17: Few more FAQ 146. FAQ 6 - Approach to design great applications with JPA?
  149. Sección 17: Few more FAQ 147. FAQ 7 - Good Practices for developing JPA Applications
  150. Sección 18: Congratulations 148. Bonus Lecture
  151. Sección 18: Congratulations 149. Congratulations

Do i need to learn native Hibernate or is JPA Hibernate enough?

Will employers distinguish between experience working with the native Hibernate API vs. the JPA version of Hibernate when they look at one's resume? I'm going to learn Hibernate soon and I'm thinking I'll just use the JPA interface ... but I don't want to limit myself if its going to make me less marketable.
Thanks for your fantastic courses

Application is not closing automatically

Thanks for your support. I have an issue with the application, this Application is not closing automatically to close it i have to press CTRL + C
is there any technique that can close this automatically after completion of whole process.
After pressing CTRL + C logger result is:
Thread-3] ConfigServletWebServerApplicationContext : Closing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@1517365b: startup date [Tue Mar 26 12:19:51 IST 2019]; root of context hierarchy

Please help he in resolving this problem

Removing Transactional Still Working

Hello,

This is not an issue with any of the lectures I simply misunderstood something and need some help. The way I understand @transactional is that it keeps the session (Hibernate) or persistence context (JPA) open and every database change in the method is under one transaction. Also if transactional is not placed on a method, a new persistence context will be created and destroyed for each line of code that accesses entity manager. I wanted to test that this understanding was correct so I took the retrievePassportAndAssociatedStudent test method and removed @transactional. You stated in the course that because fetch type is lazy, the persistence context closes after we call em.find() and therefore the following call to passport.getStudents() should cause a "could not initialize proxy" exception. Well after removing @transactional my code still tested fine with no exceptions and I really cannot understand why. I ensured fetch type is lazy both sides of relationship.

@Test
//    @Transactional
    public void retrievePassportAndAssociatedStudent() {
        Passport passport = em.find(Passport.class, 40001L);
        logger.info("Passport -> {}", passport);
        logger.info("Passport Student-> {}", passport.getStudent());
    }

Is it possible to limit results of an entity in a join?

I have a data model wherein classA has a one-to-many relationship with classB.
When I query classA by ID, I want to limit the classB results in the response.

e.g. lets say classA is a Customer class and classB is an Order class and I want to pull only last 6 (configurable) orders or so instead of lets say the whole history of last 5 years, or whatever is stored.

Right now I get the whole list.

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.