Latest Questions tagged Jpa

Browse all latest questions tagged Jpa

101
Votes
Published 07 Sep, 2022
Java - How to filter a PostgreSQL array column with the JPA Criteria API?

I am using: Hibernate 4.3.5 Spring JPA 1.6.0 Javax Persistence API 2.1 The "refcodemailing" column is defined as an array of int: int[] My entity object: @Entity @Table public class CalendarEven...

96
Votes
Published 07 Sep, 2022
Java - Set environment variable values in persistence.xml from Eclipse

I'm using OpenShift, and I'm trying to deploy my application to a local Tomcat instance for faster development. I'm using EclipseLink for DB transactions, and I've provided the environment variables O...

98
Votes
Published 07 Sep, 2022
Java - JPA select query with where clause

I want to write a select statement but can't figure out how to write the where clause... My code: CriteriaQuery query = entityManager.getCriteriaBuilder().createQuery(); query.select(query.from(Secu...

104
Votes
Published 07 Sep, 2022
Java - JPA , many-to-many relation, deleting all previous relations and entering the new relations

here i am trying out many-to-many relationship in JPA, I'v created tables "tblcourse" and "tblStudent", a student can register to many courses, create table tblcourse( id integer primary key,...

81
Votes
Published 04 Oct, 2022
Java - Hibernate - Column cannot be null

I'm doing a simple exercise to learn JPA. When I try to delete an entity of type User, which has a Collection of the other entity Score (annotated with @OneToMany) I get this error: java.sql.SQLInteg...

99
Votes
Published 06 Sep, 2022
Java - How to set autogenerated Id manually?

I have an entity called Task and it has taskId field. Problem is I need to create/update some specific tasks and JPA autogenerator doesn't allow me to set taskId manually.(It overrides my taskId) Is...

42
Votes
Published 08 Oct, 2022
Java - How to avoid join 'explosions' in JPA with Hibernate when fields from multiple tables are needed?

Let's say I have the following method in a JpaRepository: @EntityGraph(value = "Subject.allJoins", type = EntityGraphType.FETCH) @Query("select s from Subject s" + FIND_QUERY_WHERE) Page<S...

86
Votes
Published 05 Sep, 2022
Java - JPA CriteriaQuery compare Timestamp ignore time portion

Let say I have a column in Oracle DB like this: SOMETHING_TS TIMESTAMP WITH TIME ZONE And I would like to use CriteriaQuery to filter by this column. I can used native query to achieve this:...

8
Votes
Published 19 Aug, 2022
Java - What is the Java annotation in Hibernate used to auto increment a MySQL Primary Key - @Id

In this code I need the id to be the primary key and also it must be incremented. is getter and setter required for id ? @Entity public class Contact { @Id private Integer id; private String firstNa...

45
Votes
Published 07 Sep, 2022
Java - How to specify SQL comments through JPA annotations?

Is there any way to specify SQL comments through JPA annotations? Comments for tables and columns.

38
Votes
Published 11 Oct, 2022
Java - Keep getting "java.lang.IllegalArgumentException: No query defined for that name" even though I have @NamedQuery with an appropriate name

I have Hibernate JPA application. I keep getting "java.lang.IllegalArgumentException: No query defined for that name [Singer.findAll]" in the function from DAO class, even though I defined the name in...

62
Votes
Published 07 Sep, 2022
Java - How to map a MySQL JSON column to a Java entity property using JPA and Hibernate

I have a MySQL column declared as type JSON and I have problems to map it with JPA/Hibernate. I'm using Spring Boot on back-end. Here is small part of my code: @Entity @Table(name = "some_table_n...

27
Votes
Published 29 Aug, 2022
Java - What is causing a unique constraint violation when using a SEQUENCE in Hibernate?

I am using the code below to generate unique IDs for an id field. It was working fine until last week. I deleted some entities using the Hibernate interface and then it started giving a unique constra...

97
Votes
Published 15 Sep, 2022
Java - When and why JPA entities should implement the Serializable interface?

The question is in the title. Below I just described some of my thoughts and findings. When I had a very simple domain model (3 tables without any relations), all my entities did NOT implement the Ser...

80
Votes
Published 07 Sep, 2022
Java - Why is bean not found during Spring Boot?

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...