Questions tagged [jpa-2.1]

This tag is for questions specifically about new features of version 2.1 of the Java Persistence API.

The Java Persistence API version 2.1 improves JPA 2.0 with features like bulk operations, stored procedure support and new JPQL keywords.

Main features included in JPA 2.1 is:

  • Converters - allowing custom code conversions between database and object types.
  • Criteria Update/Delete - allows bulk updates and deletes through the Criteria API.
  • Stored Procedures - allows queries to be defined for database stored procedures.
  • Schema Generation
  • Entity Graphs - allow partial or specified fetching or merging of objects.
  • JPQL/Criteria enhancements - arithmetic sub-queries, generic database functions, join ON clause, TREAT option.
659 questions
4
votes
1 answer

Hibernate multiple natural id within an entity

I have a jpa entity "user" which has 2 business keys username and email. These 2 fields are unique and i have tried to define both fields as naturalId with @NaturalId, however when i search the user entity by passing only username or email, …
kenn3th
  • 1,187
  • 2
  • 22
  • 47
4
votes
1 answer

How to use loadgraph and fetchgraph from JPA 2.1 on Query DSL 4

Environment: org.hibernate:hibernate-core:5.2.14.Final org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final org.hibernate.common:hibernate-commons-annotations:5.0.1.Final org.hibernate.validator:hibernate-validator:6.0.7.Final org.sprin…
Leonel
  • 2,796
  • 5
  • 25
  • 36
4
votes
2 answers

LocalDate between using JPA 2.1 Criteria API

In my entity I have two fields : private LocalDate startDate = LocalDate.of(1900, 1, 1); private LocalDate endDate = LocalDate.of(3000, 1, 1); Using JPA Criteria API I want to select entities where LocalDate.now() > startDate and LocalDate.now() <…
Renaud is Not Bill Gates
  • 1,684
  • 34
  • 105
  • 191
4
votes
1 answer

What is the right way to use entitymanager

I have a REST client in Jersey JAX-RS which takes requests and then using Hibernate's JPA implementation retrieves the data from the database and returns a JSON. Using a shared entity manager, the performance is quite good but if there are multiple…
user3202153
  • 41
  • 1
  • 7
4
votes
2 answers

@GenericGenerator in package-info.java not working JPA

I'm trying to add a Generator on package-info.java so that I don't have to re-write same code on top of every @Entity class. But when I try to run the program Application I get an error. Session Factory could not be…
A0__oN
  • 8,740
  • 6
  • 40
  • 61
4
votes
2 answers

optional parameters jpa 2.1

I have this class, @Entity public class Message { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private long id; @Column( nullable = false ) private String mobile; @Column( nullable = false ) private String message; …
Ammar Samater
  • 529
  • 2
  • 7
  • 24
4
votes
1 answer

Is there a way to (locally) bypass or disable an AttributeConverter during a Criteria API call?

Suppose a CreditcardNumb.class with a constructor that checks if the credit-card number is valid. I then create a CreditcardNumbConverter.class to convert credit-card numbers to Strings in the database: public class CreditcardnumbConverter …
Marcelo Glasberg
  • 29,013
  • 23
  • 109
  • 133
4
votes
1 answer

Table missing after hibernate upgrade

we have just upgraded from WildFly 9 to 10 and therefore also upgraded from Hibernate 4 to 5. Our application uses entities that are derived from a abstract super entity that has a generated id field. The super class looks like…
Tom
  • 237
  • 1
  • 2
  • 13
4
votes
1 answer

Does jpa AttributeConverter apply in query clause?

I have a jpa entity like this: @Entity public class RectangleEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; @Column private Integer x; @Column private Integer y; @Column …
A.v
  • 734
  • 5
  • 26
4
votes
2 answers

JPA correct way to handle detached entity state in case of exceptions/rollback

I have this class and I tought three ways to handle detached entity state in case of persistence exceptions (which are handled elsewhere): @ManagedBean @ViewScoped public class EntityBean implements Serializable { @EJB private…
Michele Mariotti
  • 7,372
  • 5
  • 41
  • 73
4
votes
1 answer

How to select a JPA Entity by whitelisting a property of its child Entity with the Criteria API?

I'm stuck with the following hypothetical problem: Using the Criteria API (and not JPQL), and given A table full of users, each one having multiple cars @Entity public class User { @Id private Long id; @OneToMany private…
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
4
votes
2 answers

Spring data Jpa findTop and findFirst generating error Incorrect syntax near '@P0'

I am using spring data JPA 1.8.2 and trying to get top result. I am using the following method LearningSession findTopBySourceAndExternalLmsSessionIdAndCourseCodeAndLearnerEnrollmentEnrollmentStatusOrderByIdAsc(String source, String…
Basit
  • 8,426
  • 46
  • 116
  • 196
4
votes
0 answers

Different result sets for same native query when executed by SQL client and application

all. I have a weird situation when executing a native SQL query against an Oracle database. If the query is executed via SQL client software (in my case, DbVisualizer) I have one result set; if my application (Java, Spring-based) executes it, the…
Matheus Moreira
  • 2,338
  • 4
  • 24
  • 31
4
votes
2 answers

Before deleting an entity, deleting its parent reference(s), if any

It is essential to delete an entity from its parent list and the parent from the entity itself before the entity is deleted. Example (CMT in an EJB) one-to-many from State to City : public boolean delete(City city) { // Detached instance. City…
Tiny
  • 27,221
  • 105
  • 339
  • 599
4
votes
1 answer

How to do JOIN ON query using Criteria API

Since version 2.1 JPA supports join on. I found few examples how to use join on in JPQL but none for Criteria API, and here is my question: Is JOIN ON is implemented in Criteria APi? And if yes, Can anyone provide example?
user902383
  • 8,420
  • 8
  • 43
  • 63