jpa

Added @Transactional into a test to avoid org.hibernate.LazyInitializationException no Session error. Why is it needed?

﹥>﹥吖頭↗ 提交于 2021-01-29 12:28:29
问题 I annotated a test method with @Transactional to avoid: org.hibernate.LazyInitializationException: could not initialize proxy [com....OrderEntity#6def569a-ebf2-473e-b1b1-8b67e62fd17d] - no Session at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:169) at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:309) at org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor.intercept(ByteBuddyInterceptor.java:45) at org

JPA Projection with custom collection property

狂风中的少年 提交于 2021-01-29 09:47:19
问题 We are using Spring Data and trying to create a custom query with a subquery, results projection have an array and other properties, our problem is with the subquery array. public interface ProfesionalRepository extends JpaRepository<Profesional, Long> { @Query("SELECT p.id as idProfesional, " + " p.name as name, " + " p.surname as surname, " + " (SELECT a.descripcionIlt FROM Ausencia a WHERE a.profesional.id = p.id) as exclusionesCenso " + " FROM Profesional p ") List

Unable to create JUnit Test for Spring Boot Controller

China☆狼群 提交于 2021-01-29 09:36:56
问题 I am trying to write a test for a simple Controller in SpringBoot application. However, I am receiving errors due to bean creations for my TopicRepository and TopicController. I had referenced a tutorial and am little new to Spring boot development so not sure exactly how it works. How can I make the test work? ControllerTest @RunWith(SpringRunner.class) @WebMvcTest(TopicController.class) public class TopicControllerTest { @Autowired private MockMvc mvc; @MockBean private TopicService

Not save an enum value in the database, why?

感情迁移 提交于 2021-01-29 09:16:49
问题 Does not save an enum value in the database, I think that's it, or I do not understand, I try to save since the console shows me a data, but when I ask from the database I get another value @Entity @Table(name = "User") public class User implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; @Column(name = "name") private String name; @Column(name = "password") private String password; @Column(unique = true, name = "email") private String email; @Column

Not save an enum value in the database, why?

流过昼夜 提交于 2021-01-29 09:08:42
问题 Does not save an enum value in the database, I think that's it, or I do not understand, I try to save since the console shows me a data, but when I ask from the database I get another value @Entity @Table(name = "User") public class User implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; @Column(name = "name") private String name; @Column(name = "password") private String password; @Column(unique = true, name = "email") private String email; @Column

Error access two datasource with Spring Boot

我的未来我决定 提交于 2021-01-29 09:02:27
问题 I'm developing an APP that accesses two bases: Db2 and SQL Server with spring boot. When I try to access the second datasource the following error occurs: org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class It is not a problem with the driver because when I squeeze the app to run with just one of the banks it works Follow below how the project is: application.properties: Conexao sqlserver spring

Why is bean not found during Spring Boot?

早过忘川 提交于 2021-01-29 08:18:04
问题 THIS PROBLEM IS SOLVED. SEE THE CHECKED ANSWER BELOW. I reconfigured my DAOs to a more convenient way (by using JpaRepository) instead of doing all that boilerplate code manually. But now everytime I start the Spring Application it gives me the following error: *************************** APPLICATION FAILED TO START Description: Field userRepository in DAO.UserDAOService required a bean of type 'DAO.UserRepository' that could not be found. The injection point has the following annotations: -

Updating and Fetching using Pessimistic Lock

孤者浪人 提交于 2021-01-29 08:10:49
问题 Need to retrieve latest data whose status is 1 and then setting status 0 for the same using LockMode Pessimistic . so Db column are => id(autogenerated), count, category_key, status(initially 1 for all). I have pre-populated data in db where for each category_key combination I have 10000 count.... so lets say for DG_KK I have 1 to 10000 count with status 1 and then for DG_TG I have 1 to 10000 count with status 1. Now Now I when I pass key DG_KK as category_key then from db using atomic fetch

Spring Repository auto-generated method: select by given top number + order by field desc

北城以北 提交于 2021-01-29 08:08:33
问题 Spring version is 2.4.0 . I have a PlayerEntity with Integer totalRacesCount field. I need to make the top of players of different top length ordered by totalRacesCount desc. Top size must vary. I am trying to add a method in my CrudRepository<PlayerEntity, Long> to implement this. https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.limit-query-result — this section states that we can pass a numeric value top to make the limit parameterizable. This is working, but

Jpa repository and JsonIgnoreProperties return the same object differently in getOne() and in findAll() methods

牧云@^-^@ 提交于 2021-01-29 07:06:51
问题 Brief background I have two methods in an API created on Spring Boot to retrieve data from a mySQL database (via Hibernate and JpaRepository). There is a method that returns all the ocurrences in a table called test , and another one that returns the test corresponding to the id passed as a parameter in the GET call. Both API entry points (by means of the services and repositories) end up calling two JpaRepository methods ( findAll() and getOne() respectively). Problem description The problem