Questions tagged [spring-data-jpa]

0

votes
2

answer
21

Views

JPA: How to map only one property from another entity

Let's say I have two entities: @Entity public class Phone { @Id private Long id; private String number; } @Entity public class Person { @Id private Long id; private String name; } The relationship between a person and a phone is one to one. How could I access only the phone's number in the Person en...
Fabian Mendez
1

votes
1

answer
684

Views

Test Spring Data Repository in a project without a Spring Boot Application main class

I have a small project that does not contain a class to run a Spring Boot Application. In that class I only have some configuration and some repositories. I would like to test those repositories inside the small project. For that, I have the following: @SpringBootTest @DataJpaTest public class TaskR...
Manuelarte
1

votes
3

answer
185

Views

How to insert 780k records Spring Data Postgres

CSV file will be uploaded in Amazon S3 bucket. Current Implementation: Reading CSV file using OpenCSV utility's readAll which returns List Map every column value to an entity object Create a List object (Current Size :: 15000) Invoke Spring Data CRUD Repository saveAll(List objects) Out of 780k reco...
Phaneendra
1

votes
1

answer
1.3k

Views

Spring Data JPA method query with paging gives me an error

I am developing with Spring Data Jpa. I have an interface extending JpaRepository, and I want to query with Query Method and paging. I want to query 'select * from cheat where vote
PLAYMAKER
1

votes
1

answer
53

Views

Spring boot: error asking to implement all methods in JpaRepository

Why is this happening? It didn't happen when I worked on a spring project in STS few months back. I have imported the following in the class: import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; Following is my pom.xml: 4.0.0 org.springframe...
S.K.
1

votes
1

answer
35

Views

Does Spring Data JPA have any way to sum an entity column using method name resolving?

Spring Data JPA can sum colomn using specifications. But does it have any way to sum an entity column using method name resolving? Let's say I want a method sumCreditAmount to sum column with specific name, just like a method findByCreditAmount to fetch all entities with a specific creditAmount.
Riadh
1

votes
1

answer
57

Views

Spring data, find by property of a nested object

I have the following code: @Entity public class StudentEntity { @Id private String id; private Student student; ... } public class Student { private String name; private List grades; } public class Grade { private String className; private String grade; } I've set up a spring data mongodb repository...
DraegerMTN
1

votes
2

answer
43

Views

How to programmatically discover the JPA implementation and SQL dialect being used by Spring Boot?

I know it is possible to change the JPA implementation in use by Spring Boot, the default is to use Hibernate, but it's also possible to user others, like EclipseLink. It is possible to find, at application runtime, which JPA implementation is being used, and also discover which SQL dialect is curre...
André Shevantes
1

votes
2

answer
36

Views

How to enable H2 Database Server Mode in Spring Boot

I'm using a H2 database with a file using Spring Boot. In my application.properties, I have this entry: spring.datasource.url=jdbc:h2:file:c:/Testprojekte/spring-boot-h2-db But now I would like to be able to look at the database while running the application, which currently isn't possible because I...
user1119859
0

votes
0

answer
12

Views

Spring Data JPA BigList insert

I've been trying for two days now to store an array list with about six million entries in my Postgres database with Spring-Data-JPA. The whole thing works, but it's very slow. I need about 27 minutes for everything. I've already played around with the batch size, but that didn't bring much succes...
StitZle
1

votes
3

answer
106

Views

SQL Error: 23503, SQLState: 23503 in SpringBoot 2.1.4.RELEASE app

I have a SpringBoot 2.1.4.RELEASE RESTful Web Service app., using Spring Initializer, embedded Tomcat, Thymeleaf template engine, and package as an executable JAR file. I have this class: @Entity @Table(name='t_menu_alert_notification') public class MenuAlertNotification implements Serializable { /*...
carles xuriguera
1

votes
1

answer
721

Views

Query creation method gives error

My Entity has a field like @Column(name = 'workflow_status', columnDefinition = 'nvarchar(255)') private String workflow_status; So in my Controller I want to fetch the entries by workflow_status, I wrote the Query method that JPA provides List findByWorkflow_status(String workflow_status); But thi...
TweaknFreak
1

votes
2

answer
2.2k

Views

How to use Spring security without password encoding?

I'm trying to learn Spring security currently. I used BCryptPasswordEncoder to encode user password before persisting into a database Code: @Override public void saveUser(User user) { user.setPassword(bCryptPasswordEncoder.encode(user.getPassword())); user.setActive(1); Role userRole = roleRepositor...
Arjun
1

votes
2

answer
1k

Views

Trouble when changing Spring Boot version from 2.0.3.RELEASE to 2.1.0.M4

I have a working code that stops to work when I change Spring Boot version from 2.0.3.RELEASE to 2.1.0.M4 The error is: Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. *************************** APPLICATION FAILED TO START *********...
Mudassir Shahzad
1

votes
2

answer
44

Views

Spring data jpa @Query - Cannot create an “AS” alias for a result map

I map the result of the following JPQL-Query directly to a SpecialCustomDto object instead of the used javax.persistency entity object MyEntity. But I do not know, how to access the COUNT(DISTINCT e.attributeB), which will be mapped to the SpecialCustomDto. This is the query. @Repository public inte...
git-flo
1

votes
2

answer
69

Views

How to filter null values in ArrayList

I have a very big code. I faced an issue where at very starting of code, null gets inserted inside arraylist custlist i.e custlist looks like [null]. And after many lines of code, I had my code changes where I was building up Predicate using custlist as shown below: CriteriaBuilder cb = entityManag...
ASharma7
0

votes
0

answer
3

Views

How can I (if I can) extend a composed repository?

I am trying to give a Generic Parrent repository to all my 'per aggregate root' repositories which I can later use polymorphically. I have composed a parent 'composed repository'. Which is to be implemented by other specific Repositories. @Repository public interface ZoneNameJpaRepository extends Ge...
Aditya Kumar
1

votes
1

answer
180

Views

Jackson One-to-many Many-to-One infinite Loop deserialization errors

I have 2 models - Member.java @Entity @Table(name='members') public class Member { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name='member_id') private Integer id; @Column(name='member_name') @NotNull private String name; @Column(name='member_joining_date') @NotNull private Date joi...
Prateek Narendra
1

votes
0

answer
49

Views

javax.validation.UnexpectedTypeException: HV000030: No validator could be found for type: void

I am getting following Exception: javax.validation.UnexpectedTypeException: HV000030: No validator could be found for type: void while calling spring data jpa repository's save method, any specific reason behind this ? *Edited please see activitymaster and repository I have added. @Entity @Table(nam...
Mayur
1

votes
1

answer
37

Views

Spring Data JPA to deep and weird mapping

Lately I'm trying to create CRUD with many-to-one and one-to-many. I'm having following weird results, and I can't deal with it. Here's the JSON from /teams, what I've got [ { 'id': 3, 'name': 'team1', 'footballers': [ { 'id': 12, 'name': 'karol', 'age': 0, 'team': { 'id': 3, 'name': 'team1', 'footb...
iwannabeprogrammer
1

votes
1

answer
501

Views

Spring Data JPA - findAllBy query checks for null?

The documentation shows that findByLastnameAndFirstname equals to where x.lastname = ?1 and x.firstname = ?2. We know that in sql = NULL is always false. You have to use IS NULL. Let's say we have an entry firstname = 'First' and lastname IS NULL. I call this findByLastnameAndFirstname(null, 'First'...
Shawn
1

votes
1

answer
465

Views

Creating Query using Date parameters with Spring Jpa Repository

I want to execute a query via JpaRepository that uses Date objects as parameters (java.util.Date). However, each time the method from the repository is called, it returns a null value. When I pass Integer values and work with id instead of Date I don't get any errors and the query is successfully ex...
Josip Mrđen
1

votes
0

answer
123

Views

cascade persist results in null column value for a ManyToMany entity

Owner: @Entity public class Strategy implements Serializable { @Id @GeneratedValue private Long id; @ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST}) @JoinTable(name = 'StrategyHost', joinColumns = {@JoinColumn(name = 'strategyId')}, inverseJoinColumns = {@JoinColumn(name = 'host...
Tiina
1

votes
2

answer
861

Views

Filter JPA repository by multiple optional parameters

I have a simple REST service that returns user profile entity that has about 20 fields. I need to implement a functionality to filter the data where last name is required but all other fields (first name, age, city, state, zip, etc. ) are optional. Is there a way to do it using JpaRepository without...
rma
1

votes
0

answer
1.3k

Views

2 Hikari CPs with different datasource configurations?

Has anyone successfully configured two hikari connection pools with different datasources in a spring boot application? How do I do it using application.properties?
ramkris
1

votes
1

answer
354

Views

Not all Spring JPA and datasource properties working in console application

Trying to configure JPA datasource in my java console app, which uses spring-data-jpa and mysql, and it seems not all defined properties are worked: application.properties spring.datasource.url=jdbc:mysql://xyz:3306/xyz spring.datasource.username=xyz spring.datasource.password=xyz spring.jpa.propert...
Viktor V.
1

votes
1

answer
205

Views

SpEL are not read in @Query after Spring Boot 2.0.0 M7 update

I had my Spring Boot 2.0.0 M3 application developed. Everything worked just fine. But after updating to Spring Boot 2.0.0 M7 (or even to Spring Boot 2.0.0 M5 more recently) SpELs in my @Query are not longer compiled properly. For example @Query('SELECT m FROM com.mypackage.models.Model m WHERE m.st...
Serg Vasylchak
1

votes
3

answer
937

Views

Disable Spring Boot HibernateJpaAutoConfiguration but still getting a related error

@SpringBootApplication(exclude = { HibernateJpaAutoConfiguration.class, JndiConnectionFactoryAutoConfiguration.class, XADataSourceAutoConfiguration.class, JndiDataSourceAutoConfiguration.class, ...) like code above, I disable pretty much Auto Configuration Classes provided by Spring Boot, because I...
EthanZhang
1

votes
1

answer
118

Views

Get elastic search query from spring data Jpa

In my code base, I have two code for search on elastic. One is through ElasticSearchTemplte from there I build the elastic query and query on elastic. In the second one, I am querying through spring-data-jpa. In the first case, I can see my elastic search query and can directly query on ES. My quest...
Ravat Tailor
1

votes
0

answer
291

Views

At least one JPA metamodel must be present! Error in spring data application

I have created simple spring data application. I'm getting error when I run the application. The complete code is in here. The complete error trace is- Exception in thread 'main' org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation o...
Rajkumar Natarajan
1

votes
1

answer
223

Views

Spring Data JPA - Query generation from method name using query parameters on REST call

I would like to use a REST end point, pass query parameters (a combination of qp1, qp2, qp3) to it, like for example: http://localhost:8080/..../my-rest-endpoint?qp1=abc or http://localhost:8080/..../my-rest-endpoint?qp2=123 or http://localhost:8080/..../my-rest-endpoint?qp1=abc&qp2=123 or ... For...
neblaz
1

votes
0

answer
47

Views

Retrieve object by embedded identifier

I have a spring boot application which has an entity, an embedded composite key, and a repository. It looks like this: Entity @Entity class MyEntity { @EmbeddedId private MyEntityIdentifier id; private String aField, bField; } Identifier @Embeddable class MyEntityIdentifier implements Serializable...
J Smith
1

votes
2

answer
1.4k

Views

Spring-Data JPA: InvalidDataAccessApiUsageException for @Transactional

I run a Spring Boot Application wiht @EnableTransactionManagement and want to use @Transactional(readOnly = true) for some database queries. But I receive a confusing error message. I'm using Spring, Spring Boot and and Spring Data JPA. MySpringBootApplication.java @SpringBootApplication @EnableTran...
flo-ferox
1

votes
0

answer
183

Views

Test if a collection is loaded in Spring DataJpaTest

I am having troubles testing whether a collection is loaded in Spring DataJpaTest. For that I have created an entity that has id and list of items as seen below. The list should be lazy-loaded (so I am assuming it should not be loaded in the test). @Data @Entity @Table(name = 'examples') public cla...
Janar
1

votes
1

answer
79

Views

Filter Data with Spring JPA Query

I have got Persons and I just want to get the ones starting with a certain letter (the letter is from an input field). I have got the query but I can't 'use' it. And how can I make this possible? Repository: @Repository public interface PersonRepository extends JpaRepository{ @Query('From Person whe...
Doe_123
1

votes
1

answer
73

Views

What's the purpose of JpaMetamodelMappingContext?

spring-data-jpa creates an instance of JpaMetamodelMappingContext, which maintains a metamodel of JPA entities, when @EnableJpaRepositories is used. We'd like to use the CrudRepository features (findOne, delete...) in conjunction with org.springframework.data.jpa.domain.Specifications. @Query or th...
Michael
1

votes
3

answer
886

Views

How to get @Query( nativeQuery=true) result into List<MyObject>?

Hello I have a query and I want the result into list of objects, not entity. But the result is actualy a object which I should transfer to my object. Is there a way to map it directly to my custom object?
1

votes
0

answer
242

Views

How can I improve the response speed of request with a projection in Spring Data JPA?

I have a goal repository that returns a list Goals based on a competition: public interface GoalRespository extends JpaRepository { @Query(value = 'SELECT * FROM goal g ' + 'JOIN matches m ON g.goal_match = m.idmatch ' + 'JOIN competitions c ON m.competition = c.idcompetitions ' + 'WHERE c.idcompet...
Matias Diez
1

votes
0

answer
351

Views

Using @DataJpaTest when multiple datasources are configured [duplicate]

This question is an exact duplicate of: Using @DataJpaTest with multiple DataSource and custom repository implementation [duplicate] how to use @DataJpaTest with multiple datasourse 1 answer My application is configured with two datasources, following this example: https://github.com/snicoll-demos/...
Brad Mace
1

votes
0

answer
76

Views

Custom JpaRepository no found property saveEntity

You need to create a generic JpaRepository, in order to handle all transactions made by the system. Follow this example here. It was a bit different from the implementation, because my goal is not to do a search but to manipulate a save method. Inteface GenericRepository: @NoRepositoryBean public in...
user8223022

View additional questions