spring-data-jpa

Transactional annotation doesn't solve org.hibernate.LazyInitializationException

北战南征 提交于 2021-01-29 06:20:04
问题 I'm writing a simple Spring Data JPA application. I use MySQL database. There are two simple tables: Department Employee Each employee works in some department (Employee.department_id). I have two entity classes: @Entity public class Department { @GeneratedValue(strategy = GenerationType.IDENTITY) @Id private Long id; @Basic(fetch = FetchType.LAZY) @OneToMany(mappedBy = "department") List<Employee> employees; } @Entity public class Person { @GeneratedValue(strategy = GenerationType.IDENTITY)

Cannot use save() to insert when previously importing data using data.sql

五迷三道 提交于 2021-01-29 06:08:08
问题 I'm terribly sorry if I can't start another post which is connected to my previous one but my question is somewhat different. I noticed that I really can save new data in my database as long as I never added data to the database by using the line spring.datasource.initialization-mode=always in my application.properties and made a data.sql file with a few insert statements. Once I insert the data using that file, I can access the data and show it to the user, but I can't create any new data

Using JPA repository access in constructor of Service class

半世苍凉 提交于 2021-01-29 05:25:44
问题 I have spring boot app with a service (annotated @Service ) and having several JPA repository interfaces. Now I want to read entries form a database during the start of the service cause the JPA repository and the database connection is done before anything else. So I have decided to put that code into the constructor of the service. The question is: Is this a correct way to initialise some attributes of a service only once at the start of the application (configuration which is stored in

NumberFormatException while trying to authorize user

a 夏天 提交于 2021-01-29 05:22:00
问题 I'm trying to set up small web application in spring using bootrap and thymeleaf. I have no idea what's going on, because I have already one user in databe and I'm trying to log on it. When I pass wrong credentials is okey and spring-security doesn't pass me futher. But, when I pass corrent credentials, there is a NumberFormatException exception thrown from spring-security-core saing that it cannot parse my password to double. Password is hashed by BCrypt, but even when it wasn't hashed I had

Spring boot jpa integreated with javafx service null

假如想象 提交于 2021-01-29 03:25:52
问题 I have integrated spring boot jpa with javafx app. The integration was successful and fx screen loaded the scene, the problem was the the service is getting null on an @Autowired annotated field. You can find my whole project on github boot-fx. pom details <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.3.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring

Spring boot jpa integreated with javafx service null

别来无恙 提交于 2021-01-29 03:18:45
问题 I have integrated spring boot jpa with javafx app. The integration was successful and fx screen loaded the scene, the problem was the the service is getting null on an @Autowired annotated field. You can find my whole project on github boot-fx. pom details <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.3.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring

How to pass column name dynamically inside a @Query annotation using Spring data JPA

馋奶兔 提交于 2021-01-29 02:04:34
问题 I have entity like: @Id @Column_name = "abc" int pk; @Column_name = "def" int id; And I have Repository as: interface fetchDataRepository extends jpaRepository<className, int> { @Query("Select S_Test.nextVal from dual"); Long generateId(); } In above example S_Test is hardcoded sequence name. But the problem is that I want to pass sequence name dynamically as follows: Long generateId(@Param("sequenceName") String sequenceName) and use inside @Query annotation as: @Query("Select :sequenceName

How to handle DataIntegrityVilolationException while saving a list in Spring Data JPA?

别等时光非礼了梦想. 提交于 2021-01-28 22:38:46
问题 I am using Spring Data JPA in a Spring Boot Application, with MYSQL. There I am saving a list of entities with unique constraint over a field. Out of the list of entities, there is one entity that will throw DataIntegrityViolationException due to the unique constraint. I noticed that none of the entities get persisted in that case, even those that does not violate the unique constraint. What should be the ideal approach in this case so that those entities which do not violate the unique get

Exclude certain DataSource(s) from HibernateJpaAutoConfiguration

﹥>﹥吖頭↗ 提交于 2021-01-28 21:51:53
问题 I have a project with 2 DataSources. One is for PostgreSQL and other is for ClickHouse. No problem so far. I intend to use ClickHouse with native SQL via JDBC only. But I would like to use JPA based repositories with PostgreSQL datasource. And if I add spring-boot-starter-data-jpa dependency, HibernateJpaAutoConfiguration kicks in for ALL registered DataSource beans . ClickHouse is not a transactional relational DB and its JDBC implementation is very limited and basic, never intended for use

Exclude certain DataSource(s) from HibernateJpaAutoConfiguration

邮差的信 提交于 2021-01-28 21:03:59
问题 I have a project with 2 DataSources. One is for PostgreSQL and other is for ClickHouse. No problem so far. I intend to use ClickHouse with native SQL via JDBC only. But I would like to use JPA based repositories with PostgreSQL datasource. And if I add spring-boot-starter-data-jpa dependency, HibernateJpaAutoConfiguration kicks in for ALL registered DataSource beans . ClickHouse is not a transactional relational DB and its JDBC implementation is very limited and basic, never intended for use