Questions tagged [jpa]

The Java Persistence API (JPA) is a Java specification for accessing, persisting, and managing data between Java objects/classes and a relational database. It is part of the EJB 3.0 specification and is the industry standard approach for Object to Relational Mapping (ORM).

-1
votes
0answers
8 views

Java Code Generation for Persistence for a given Data model

I am looking for Java Code generation tool for persistence for a defined Data Model. The approach we are looking for is, define a data model for entity objects Use some kind of code generation to ...
0
votes
0answers
4 views

Trying to assign Oracle Table type to a Struct Entity using Eclipselink

Trying to set an Oracle Table type inside of an entity and am unable to find a way to do so. I was able to assign an OracleObject or Table type as a direct parameter in my call to a stored procedure ...
0
votes
0answers
16 views

Spring-Boot JPA repositories: how to flush a delete before a save?

Having two JPARepository, ARepository and BRepository, where the entities are as below: @Entity public class A{ @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "...
0
votes
1answer
35 views

How to OneToMany relation in JPA

I'm not sure what I'm missing to make a onetomany relationship using JPA. Field username_id in second table is created as MUL key, I'm expecting Foreign Key, what's wrong? @Entity @Table(name="...
0
votes
1answer
10 views

Web service with multi tenant in spring: postgres vs mongodb

I would like to create a simple project using spring to control the status of some customers, with different environments. So a customer can have two environments (dev and prod), and others may have ...
0
votes
0answers
19 views

JPA: Column is not the same datatype as referencing column

While trying to run my app, I noticed nothing was loading. It turns out I'm getting a Column 'Graad.GraadNumeriek' is not the same data type as referencing column 'Persoon.GraadNumeriek' in foreign ...
0
votes
0answers
10 views

JPA/Eclipselink: create custom annotation for mapping enumerations

I want to create or extend a JPA annotation for mapping Enums. for example, @Enumerated is missing a couple of features, it only allows mapping the Enum index or string(getName). I would like to ...
1
vote
1answer
23 views

Paging with Spring MVC, JPA and Datatables

I want to use paging in my Spring controller and in my view where I use datatables. In the controller I use a Spring data repository with paging support: @GetMapping("my/url") public String listAll( ...
0
votes
1answer
22 views

Not able to resolve an embedded entity in Criteria API

I am trying to perform a fetch using Criteria API with restrictions on the variable of an embedded entity. But I am getting the below error, org.hibernate.QueryException: could not resolve property: ...
0
votes
2answers
29 views

SQL Query with one to many left join exclude any not existing

I would like to run sql query that brings me the children who did not eat any cake between 2 dates. 2 Tables: * Child - id, name * Cake - child_id, eat_timestamp One child (Andy) has eaten 2 ...
0
votes
1answer
69 views

How to convert SQL Query using CriteriaQuery

I want to convert my sql query from SQL to CriteriaQuery, I have this sql query: 1) SELECT * FROM table AS t WHERE id = (SELECT MAX(id) FROM table AS t WHERE t.element_id = 354 AND (name <> '...
1
vote
0answers
18 views

CASE Statement without @Query Spring JPA MYSQL

Is it possible to use CASE statement in SPRING JPA without Explicitly defining the whole query in @Query Annotation. I have a big query: select m.a, m.b, m.c from Messages m Inner Join Replies r on ...
-3
votes
0answers
35 views

Best approaches to adding dynamic fields to database using Spring boot 2 and JPA

How to add dynamic field into existing table? and fetch those new columns using JPA/hibernate. It's like user can add new field front end that field along with data need to stored in DB Table.
0
votes
3answers
22 views

Querying an unmapped Entity using jpa and hibernate

I am new to spring,hibernate and jpa. The problem statement is to hit some reporting database and the records from the table.I am using spring boot to create my REST application.Now the table i want ...
-1
votes
0answers
18 views

Hibernate lazy loading isn't working in @OneToOne Mapping

Although Lazy loading applied still it is running all 4 queries, but I'm fetching only System.out.println("Author's Name: " + b.getEmail()); public class Author { @Id @...
1
vote
0answers
43 views

Spring Data Jpa repositories using fragments how to apply query hints and entity graph

Starting with Spring 5, we have the option to enrich our JPA repository with multiple fragment repositories. The mechanism is quite simple: declare then implement an interface. public interface ...
0
votes
3answers
46 views

How save composite Class

i have this class, i want to persist this class, but just i get errors. @Entity @Table(name = "Participant") public class Participant { @Id @GeneratedValue(strategy = GenerationType.AUTO) ...
0
votes
1answer
46 views

SpringBoot 2 use HikariCP can't connect to MySQL

Phenomenon When Sprint Boot project use application.properties as default configure file can connect to MySQL,but when use application.yml the project can‘t connect to MySQL. Error Message Caused ...
0
votes
1answer
30 views

JPA criteria query for company and its employee count

I am using JPA repositories. I have a Company table with one-to-many relationship with Employee table. I want to get list of companies with employee count who's last name is x. I am trying to use ...
0
votes
1answer
23 views

MySql view shows wrong information from the database in jpa query

I have a view from mysql mapped by hibernate in a java project, when I first map the entity and consult the information, it gives the information I have in my DB, but when I insert new data into the ...
0
votes
2answers
34 views

How get participants with jpa?

i have this entity: @Entity @Table(name = "Participant") public class Participant { @Column(name = "user") User user; @Column(name = "meet") Meet meet; @Enumerated(EnumType....
0
votes
0answers
6 views

HQL Sleep Query With JPA Criteria

I have lock test. I want to see response of database after 5 seconds. I am using JPA createQuery @Override public void testLock() { System.out.println(entityManager); entityManager....
0
votes
1answer
16 views

How put a extra attribute in table oneToMany?

I have this code public class Meet implements Serializable { @OneToMany(fetch = FetchType.EAGER) private Set<User> users = new HashSet<>(); } This code create a new ...
0
votes
1answer
14 views

How to fix Unicode character resolution in docker container running gradle?

I was trying to run hibernate core java tests inside a container using gradle. I am getting this error during gradlew test. Task :hibernate-core:compileTestJava FAILED FAILURE: Build failed with an ...
0
votes
1answer
30 views

How to run a custom ddl script on startup of Spring Boot 2

Is it possible to run a custom ddl script on startup after spring.jpa.hibernate.ddl-auto = create has created the model entities in the database? Currently I do a lot of changes to the models ...
0
votes
0answers
13 views

Conflicts with Spring Contract Tests and JPA

We are trying to do Spring Contract tests with our application. Our application is using JPA for database access. In our application, we are trying to mock the return from the database repository ...
0
votes
1answer
38 views

How to use @Autowired in EntityListener class?

I have a class DatabaseInitializer which inserts some data via crudrepositories into my database. Now I added an EntityListener which should update a number in another table (table 2), if the date of ...
0
votes
0answers
35 views

Hibernate still querying N + 1 although using custom query

I created a bidirectional OneToOne relationship between two entities Review and Reviewer. Reviewer is the owning side and Review te inverse side. I noticed when I called findByBedrijfId() method (back ...
0
votes
2answers
12 views

Get value of Id being created in database with hibernate

I am developing an e-commerce website and integrating with payment gateway. During this implementation, my application sending some information to the payment gateway. Along with some order ...
0
votes
1answer
25 views

How to fix 'no entitymanager with actual transaction' when deleteallby method gets called?

I am building a spring boot back-end and want to make a rest end-point, that deletes all item by the suppliers id. When I call the rest end-point, I get 'no entitymanager with actual transaction ...
0
votes
0answers
16 views

Configure Spring Boot Multiple Datasources based on database configurations stored in the Main Database

I am currently coding an application in Spring Boot and I have ran into a problem with the datasource. The app has one datasource which connects to the database where the other datasource ...
0
votes
1answer
45 views

Proper way of creating new record via Spring + Hibernate

I'm trying to create new object and persist it in DB. In project, I have Spring-boot, Hibernate and Thymeleaf. To provide data, I use this form: <body> <form th:object="${malt}" th:...
0
votes
1answer
23 views

Delete on many to one relation is not persisting

I am trying to delete an entity from a Many to One relationship. It doesn`t throw any error, but it seems that the item is not deleted and I do not know why. These are my classes: Client Entity: ...
0
votes
2answers
29 views

Is there better solution to map lots of fields entity into two tables?

I am getting data with 50 fields. How to map into two tables in jpa, in which I required only three fields and rest of fields I need to only pass to downstream? This is for a new spring data jpa, ...
0
votes
1answer
21 views

Entity Manager - create query - nested select

I'm trying to execute the next: em.createQuery("SELECT processId FROM (SELECT processId FROM table_name WHERE processName like '%abcaccz%')") But I'm getting: Method threw 'java.lang....
0
votes
0answers
28 views

How the service will inject an object, which it needs e.g. 5 minutes to be calculated?

My question is partly a theoretical one and I would like to know, what would happen if we want to inject an object, which is in the example below 'user', through a service showed when the object ...
0
votes
0answers
21 views

Does the fetching performance differ in FetchType.LAZY and Left Join Fetch

I am a new person for Hibernate & JPA. Now, I am curious about the running performance between FetchType.EAGER and Left Join Fetch. For example. Option 1 @Entity @Table(name = "EMPLOYEE") ...
0
votes
0answers
24 views

Can't truncate PostgreSQL tables with JPA

I'm trying to quickly delete all data from multiple tables using Spring Data JPA. From what I've read, the fastest way to do this is to truncate the tables. My code looks like this: @Service public ...
0
votes
1answer
16 views

I need a query to get result from the jpa repository

I have two tables (policy, claims) join by policyId, I need the details of the Policy from Claims by counting the no of claims against the each Policy and the checking the count value > parameter ...
0
votes
0answers
23 views

How can I use SUBSTRING_INDEX in JPA?

For an example I have a String "some_random_string_first:random_string_that_i_ignore_during_query:some_random_string_second". Here I want to get some_random_string_firstand ...
0
votes
0answers
31 views

How much longer brand new Spring app will emit warning about spring.jpa.open-in-view?

There were a long discussion in https://github.com/spring-projects/spring-boot/issues/7107 about spring.jpa.open-in-view default 29 Sep 2017 in you decided keep it enabled by default and print ...
1
vote
1answer
48 views

Spring Data JPA: using object retrieved with `JpaRepository.getOne(id)`

In my Spring Boot application generated with JHipster (v6.0.1) Kotlin blueprint (v0.8.0) I have the following POST request handler @PostMapping("/book") fun createBook(@RequestBody ...
0
votes
0answers
35 views

Why I Can't Do Mapping using Many-To-One

Do anyone knows why I can't do mapping using many-to-one? This is my model @Entity(name="trxrawatjalan") public class Rawatjalan implements Serializable { @Id @...
0
votes
0answers
18 views

H2 database results different depending schema source

I save a number of big decimals in the database, marked with ‘’’precision = 4, scale = 16’’’ on the entity field. When I create the database purely with hibernate create/create-drop, saving a value ...
1
vote
2answers
55 views

Auto generated id not cascading on EmbeddedId in child entity in Hibernate

When trying to insert an Entity - Awith a set Another Entity B, B should get the Auto generated Id from A but its null. Tried and failed: @MapsId("taskPKId.storyId.id") - Same error. @Embeddable ...
1
vote
2answers
25 views

Issues saving foreign key in Hibernate one-to-one relationship

I have the following one-to-one Hibernate relationship: USER @Entity @Table(name=User.TABLE_NAME) public class User { public static final String TABLE_NAME = "user"; @Id @...
0
votes
0answers
15 views

EmbbedId null in spring boot

I'm trying to model a business paying dividends and exposing a REST API to interact with such model. I'm using spring-boot 2.2.0 Here is my Dividend entity: @Entity public class Dividend { @...
0
votes
0answers
17 views

Load Persistence.xml from environment

I'd like to deploy my application on multiple servers. Those servers have different database-managers. (one is Oracle, the other is Postgres in this case). These require different persistence unit ...
0
votes
0answers
24 views

Specification join tables with order and sort by

I want to write a Specification which contains join, inner query and dynamic order and sort by. The query which I need to convert to specification is SELECT t.machine_id AS id, t.machine ...
0
votes
0answers
32 views

Hibernate throws classcast exception for @JoinFormula can not cast to @Column. How can i resolve this?

I'm working on Existing spring-boot project. Employee entity of application is mapped with 78 other entities. Each entity has composite key. When i run the project i get an error here :- @ManyToOne ...