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

From Wikibooks:

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

Examples

The current version of the JPA specification is JPA 2.1 (JSR 338), released on 22 April 2013. It includes several improvements, such as type-converter and stored procedures.

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.

45932 questions
12
votes
3 answers

Hibernate @OrderBy for nested properties

I need to use @OrderBy (JPA, Hibernate as provider) to sort collection for nested property: @OneToMany(mappedBy = "paramSpec", cascade = CascadeType.ALL) @OrderBy("release.ordinal") private List pkdbParams; In…
Piotr Sobczyk
  • 6,015
  • 6
  • 42
  • 65
11
votes
2 answers

How to use JPA Criteria API when joining many tables

This is the further question to this: How to use JPA Criteria API in JOIN CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder(); CriteriaQuery criteria = criteriaBuilder.createQuery( Company.class ); Root companyRoot =…
Sami
  • 2,179
  • 11
  • 43
  • 77
11
votes
1 answer

How to use Lucene and JPA?

I would like to use Lucene to provide full text search capability on some of my java objects stored with EclipseLink in my Postgresql database. I saw Hibernate has an integrated solution for Lucene called Hibernate Search, but I can't find anything…
Thomas
  • 1,757
  • 2
  • 12
  • 20
11
votes
3 answers

Hibernate 4 ClassCastException on LAZY loading while EAGER works fine

I have the following JOINED inheritance root entity for geographic areas (like continents, countries, states etc.): @Entity @Table(name = "GeoAreas") @Inheritance(strategy = InheritanceType.JOINED) public abstract class GeoArea implements…
Kawu
  • 12,601
  • 31
  • 109
  • 189
11
votes
3 answers

Need help creating JPA criteria query

I'm building my first Java EE web application using Glassfish and JSF. I'm fairly new to the criteria query and I have a query I need to perform but the javaee6 tutorial seems a little thin on examples. Anyway, I'm having a hard time creating the…
Alan B. Dee
  • 4,982
  • 4
  • 31
  • 28
11
votes
3 answers

Using MySQL, why doesn't Hibernate/JPA create foreign key constraints for me?

Documenting this here because I just wasted an hour trying to figure this out. I have an entity Foo with: @ManyToOne(optional = false) @JoinColumn(name = "barId") private Bar bar; Why does Hibernate not create a foreign key constraint on foo.bar ->…
George Armhold
  • 29,784
  • 45
  • 147
  • 224
11
votes
4 answers

How can I query a null in a Long value without getting "Expected NUMBER but got BINARY" from OracleDB?

I'm using JPQL and want to query for a null value in a Long field. But I always get a ORA-00932: inconsistent datatypes: expected NUMBER got BINARY. As I've seen there are many people who have problems with this, but does anybody has a workaround…
MikeO
  • 209
  • 1
  • 6
  • 13
11
votes
3 answers

Play! framework immediate save?

In Play! if you call this: void method() { User u = User(); u.name = "bob"; u.save(); while(true){/* endless loop */} } Nothing will actually be saved into the db (The Play! class needs to get the hand back to flush the saves.) How do I have to…
Flavien Volken
  • 14,820
  • 9
  • 78
  • 105
11
votes
1 answer

Retrieving single value using JPA?

Is there any support by JPA to map single values to scalar data types? For example, to map NUM in the following query SELECT COUNT(*) AS NUM FROM EMPLOYEES to some variable int numerOfEmployees or do I have to use JDBC for such use cases?
Jan Algermissen
  • 4,752
  • 4
  • 24
  • 38
11
votes
5 answers

Saving bidirectional ManyToMany

I have two entity classes annotated in the following way @Entity class A { @ManyToMany(mappedBy="A", cascade=CascadeType.ALL) private List b; .. } @Entity class B { @ManyToMany(cascade=CascadeType.ALL) private List a; .. } If I…
Kim L
  • 6,323
  • 9
  • 35
  • 43
11
votes
2 answers

ORDER BY "CASE column" in JPA

I want to ORDER BY the case statement, is it possible? How can I do it? SELECT new com.systemname.to.UserDataHolder(u.userId, CASE WHEN (u.place.cityId = :cityId) THEN 1 WHEN (u.place.stateId = :stateId) THEN 2 ELSE 3 END) FROM User u ORDER…
Gondim
  • 2,760
  • 7
  • 39
  • 59
11
votes
5 answers

What impact does the @embedded annotation mean?

How does the Embedded annotation affect the database? How will SQL queries need to change? What's the typical usecase for using the annotation?
user48545
  • 2,671
  • 9
  • 27
  • 41
11
votes
2 answers

Does JPA have something like hibernates '@GenericGenerator' for generating custom ids?

I'm trying to create a custom way of computing and passing unique id's that follow my own pattern. Hibernate has the @GenericGenerator annotation that lets you map a custom class for computing a unique id and assigning it back to the @Id…
Dimman
  • 1,024
  • 3
  • 13
  • 20
11
votes
3 answers

Is calling persist() flush() and refresh() in one method to persist an entity the right way?

My intention is to return a newly persisted entity just in the same business call to a client in order to get the generated primary key needed for further business logic. Calling a finder method to find the entity by name or some known attributes…
mwalter
  • 955
  • 2
  • 11
  • 29
11
votes
2 answers

How do I keep entities (or their associations) attached to the current persistence context across multiple requests (using Wicket & JPA)?

I am working on a Wicket-based web app on Java EE. I am trying to find a way to ensure that any entities used as model objects are always attached to the current EntityManager before Wicket tries to render any components. This way, when the…
pbitty
  • 131
  • 6
1 2 3
99
100