Questions tagged [jpa]

The Jakarta Persistence API (formerly Java Persistence API) (JPA) is a Java specification for accessing, persisting, and managing data between Java objects/classes and a relational database. JPA was defined as part of the EJB 3.0 specification as a replacement for the EJB 2 CMP Entity Beans specification. JPA is now considered the standard industry approach for Object to Relational Mapping (ORM) in the Java Industry.

The excerpt above is from Wikibooks:

Examples

The current version of the JPA specification is JPA 3.1, released on Apr 06, 2022.

Useful links

Related tags

FAQ

Spring Data JPA Update @Query not updating? While this question is about Spring Data JPA the underlying problem is about understanding the 1st level cache of JPA. See also the many duplicates pointing to that question.

One to many relationship doesn't work Spring boot jpa Again, asked in the context of Spring Data JPA it is really about JPA. It describes a common problem/misunderstanding with regard to bidirectional relationships.

51422 questions
14
votes
3 answers

JPA: check whether an entity object has been persisted or not

Is there a general method that can if(entity is persisted before){ entity = entity.merge(); }else{ entity.persist(); } So the method contain above logic is safe everywhere?
Dreamer
  • 7,333
  • 24
  • 99
  • 179
14
votes
2 answers

Is it a good practice to use JPA entities as domain models?

or to create a domain layer that is consisted of domain models and talk to JPA entities for database accessing? What are the pros and cons for both approaches ? Thanks!
Bobo
  • 8,777
  • 18
  • 66
  • 85
14
votes
2 answers

How to use StatelessSession with Spring Data JPA and Hibernate?

I'm using Spring + Spring Data JPA with Hibernate and I need to perform some large and expensive database operations. How I can use a StatelessSession to perform these kind of operations?
jelies
  • 9,110
  • 5
  • 50
  • 65
14
votes
4 answers

columnDefinition = "TEXT" for all types of databases

Locally I use mysql, so when I use @Column(columnDefinition = "TEXT") Unfortunately application have to run at different databases too, I've not been told which ones just "at all". Is it possible to make something with similar effect, but…
akuzma
  • 1,592
  • 6
  • 22
  • 49
14
votes
5 answers

Generate JPA2 Entities from Existing Database using Maven

Generate JPA 2 Entities from existing Database I want to do same but using maven build. Please suggest the plugin. As i googled it, i found the metamodel generation of JPA using JPA annotation entities.Didn't find anything related to this question.
Shashi
  • 12,487
  • 17
  • 65
  • 111
14
votes
4 answers

Should I use Spring or Guice for a Tomcat/Wicket/Hibernate project?

I'm building a new web application that uses Linux, Apache, Tomcat, Wicket, JPA/Hibernate, and MySQL. My primary need is Dependency Injection, which both Spring and Guice can do well. I think I need transaction support that would come with Spring…
Trevor Allred
  • 888
  • 2
  • 13
  • 22
14
votes
1 answer

JPA-style Criteria/CriteriaBuilder queries from Hibernate Session

I have an application that uses Hibernate 4.x, and it is currently using the native Hibernate APIs (meaning that I have a SessionFactory and Sessions). I just noticed that the existing Criteria API is deprecated in favor of JPA's (superior) Criteria…
Adam Batkin
  • 51,711
  • 9
  • 123
  • 115
14
votes
2 answers

Is there any available API to represent various units of item like KG, Litre, Metre, KM, etc

In my project, somewhere I have to work with a unitOfIssue of Items. Now, various items of course can have different units of representation. So, I was searching for some API or some way, to elegantly handle this situation. Is there any available…
Rohit Jain
  • 209,639
  • 45
  • 409
  • 525
14
votes
1 answer

Building a query using NOT EXISTS in jpa criteria api

I have two tables named as table1 ,table2.Both the tables are having same no of fields.There is no relation between these two tables.My requirement is I want all the records in table1 which are not there in table2. So I have written a query using…
aaaa
  • 487
  • 4
  • 13
  • 24
14
votes
2 answers

jpql date comparison today

I need a jpql query to find all the LoadFileHistory which finishDate be greater than the currente date (since 00:00:00). For instance greater than 27/11/2012 00:00:00. I already have this one "select o from LoadFileHistory o where o.finishDate =…
Manuel
  • 347
  • 2
  • 6
  • 14
14
votes
2 answers

JPA / Hibernate OneToMany Mapping, using a composite PrimaryKey

I'm currently struggling with the right mapping annotations for a scenario using a composite Primary Key Class. First, what I am trying to achieve in words: I have 2 classes: group and FieldAccessRule. A Group can have many FieldAccessRules, while a…
dognose
  • 20,360
  • 9
  • 61
  • 107
14
votes
1 answer

JPQL ManyToMany select

I have a Many To Many relationship between two entities called: Car and Dealership. In native MySQL I have: car (id and other values) dealership (id and other values) car_dealership (car_id and dealership_id) And the query I want to make in JPQL…
gtgaxiola
  • 9,241
  • 5
  • 42
  • 64
14
votes
2 answers

JPA Repository: javax.persistence.NonUniqueResultException: result returns more than one elements

Using the below code I am unable to get the results of my query. Whether I use Map
Ben
  • 60,438
  • 111
  • 314
  • 488
14
votes
5 answers

Eclipse error on mapping with @EmbeddedId

I have an entity with composite key so I use the @Embeddable and @EmbeddedId annotations. Embeddable class looks like this : @Embeddable public class DitaAdminAccountSkillPK implements Serializable { @ManyToOne @JoinColumn(name = "admin_id") …
user1622058
  • 453
  • 3
  • 7
  • 16
14
votes
2 answers

@javax.persistence.Column( updatable=false )

If I define a field as non-updatable, does that mean that the field can't be updated at all, ever? What I'd like to do is prevent the field from getting updated when I save an entire entity object, but still be able to write queries that explicitly…
Mike Baranczak
  • 8,291
  • 8
  • 47
  • 71