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
1 answer

Why does EntityManager insert instead of updating?

I have a main thread where I get an object from database, then close the EntityManager, then put the object into a queue. A worker thread makes some business with the object, then puts it into a finished queue. Then the main thread gets the object…
user4039871
14
votes
2 answers

In JPA, relational databases and etc., What is a Tuple?

I'm studying Hibernate and JPA, and I am finding this term all the time. Could someone explain me in a practical and didactic way, what is this term, and how it relates to JPA / Hibernate / Databases ? I wonder if it's a type of data structure that…
Loa
  • 2,117
  • 3
  • 21
  • 45
14
votes
2 answers

Field's value of native query in JPA

How to get value of some fields in a native query (JPA)? For example I want to get name and age of customer table: Query q = em.createNativeQuery("SELECT name,age FROM customer WHERE id=..."); Note: I don't want to map results to entities. I just…
Nav
  • 4,450
  • 10
  • 53
  • 84
14
votes
5 answers

How to read bytea image data from PostgreSQL with JPA?

I have PostgreSQL database and there is column 'image' with datatype 'bytea'. I cannot modify columns or database configurations. JPA annotated POJO contains followign mapping @Column(name="image") private byte[] image; The returned data is in…
Bhushan
  • 567
  • 2
  • 5
  • 14
14
votes
1 answer

Error attempting to apply AttributeConverter

I was using JPA AttributeConverter with spring boot 1.2.1 RELEASE and it worked fine. But I get the following error after upgrading to spring boot 1.3.0.RELEASE Caused by: javax.persistence.PersistenceException: Error attempting to apply…
Appy
  • 601
  • 2
  • 7
  • 12
14
votes
4 answers

How to fetch EntityGraph dynamically in Spring Boot

I am developing an application using Spring Boot using JPA. In the application I am exposing a rest API. I do not want to use Spring data rest as I want to have full control of the data. I am not able to figure out how to use EntityGraph…
Ashwani K
  • 7,880
  • 19
  • 63
  • 102
14
votes
3 answers

JPA: Saving List of values as comma separated values

I am receiving a simple list of values part of JSON request which I want to save as comma separated values. Tried using following but it did not work. @Column(nullable = true) @GeneratedValue(strategy = GenerationType.AUTO) private ArrayList
Himanshu Yadav
  • 13,315
  • 46
  • 162
  • 291
14
votes
3 answers

No qualifying bean of type [org.springframework.transaction.PlatformTransactionManager] is defined

I am using 2 Weblogic data sources; In my XML configurations I have 2 persistence units, 2 entityManagerFactories, and 2 transactionManagers. The files are as follows: persistence.xml:
jcthomas113
  • 392
  • 1
  • 4
  • 21
14
votes
5 answers

postgresql: Converting bytea to bigint

I have to convert a bytea entry for a query to bigint. How could this be done? More Info: I have a hibernate repository as below - @Query(value = "update Sample_Table set other_id = ?1 where id = ?2", nativeQuery = true) void…
Manish Shukla
  • 163
  • 1
  • 1
  • 7
14
votes
5 answers

JPQL: cast Long to String to perform LIKE search

I have the following JPQL query: SELECT il FROM InsiderList il WHERE ( il.deleteFlag IS NULL OR il.deleteFlag = '0' ) AND il.clientId = :clientId AND ( LOWER( il.name ) LIKE :searchTerm OR il.nbr LIKE :searchTerm OR LOWER(…
Kawu
  • 13,647
  • 34
  • 123
  • 195
14
votes
5 answers

ejb3-persistence.jar source

Well, I must be brain-damaged, because I can't find the java source for Sun's persistence.jar or JBoss's ejb3-persistence.jar JPA package. They are open-source aren't they? I looked all over the java.sun.com site as well as the GlassFish wiki, but…
Randy Stegbauer
  • 1,104
  • 2
  • 11
  • 25
14
votes
4 answers

Spring data JPA for returning specific fields

Does Spring Data have a mechanism for returning specific fields? I'm familiar with the syntax: Invoice findByCode(String code); How about this: Integer findIdByCode(String code); which returns the id field only. Or Tuple findIdAndNameByCode(String…
Gilbert
  • 3,584
  • 2
  • 26
  • 30
14
votes
1 answer

Where to place @SqlResultSetMapping in case of @ConstructorResult

I'm trying to map a non-entity pojo with the createNativeQuery method of entityManager of jpa. By using something like this @SqlResultSetMapping(name="ResultMapping", classes={ @ConstructorResult( targetClass=Employee.class, columns={ …
14
votes
3 answers

JPA/Hibernate Join On Constant Value

I am trying to join to different entities from the same table using a constant value in the join statement. In SQL, I would do something like this... SELECT * FROM owner o JOIN types t on t.owner_id = o.id AND t.type = 'A' -- …
EvilJoe
  • 165
  • 1
  • 2
  • 8
14
votes
2 answers

How to save and load a large Graph structure with JPA and Hibernate?

I'm trying to persist and load the following simple structure (resembling a directed graph) using JPA 2.1, Hibernate 4.3.7 and Spring Data: Graph.java @Entity public class Graph extends PersistableObject { @OneToMany(fetch = FetchType.LAZY,…
Martin Häusler
  • 6,544
  • 8
  • 39
  • 66