Questions tagged [jpa-2.0]
This tag is for questions about the version 2.0 of the Java Persistence API. The focus of JPA 2.0 was to address features that were present in some of the popular ORM vendors but could not gain consensus approval for JPA 1.0.
3,212
questions
0
votes
0
answers
9
views
Orphan removal triggering constraint violation, deletes after update
My problem is as follows, I have 2 classes like this
@Entity
public class Parent {
...
@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, orphanRemoval = true)
private ...
0
votes
1
answer
19
views
How can we write JPA query for below SQL query
how to write jpa query for below sql without using native sql query
select * from emp where emp_id=123 and (emp_name="ABC" OR emp_name is NULL) order by salary
0
votes
3
answers
38
views
How to map specific column in entity class
I have two tables Users and UserRoles. These are the entity class I have created,
@Entity
@Table(name="users")
public Users {
@Id
@Column(name = "id")
private Long userId;
@...
0
votes
1
answer
15
views
When using JPA2 EntityListener, how does it work if i use the in clause to update multiple rows?
query : update Order set f='1' where key in (1,2,3,4,5)
@PostUpdate
public void postUpdate(Order order) {
....
}
I wonder what happens if I work as above.
1
vote
1
answer
67
views
Hibernate 5 migration Issue with Multilevel Joined table Inheritance with Hibernate 5.4 DiscriminatorColumn
I am working on migrating a legacy Hibernate project from version 4.1 to 5.4. The code has Multilevel Joined table inheritance using a dedicated DiscriminatorColumn. The code was working fine in ...
0
votes
1
answer
111
views
How to fix JPA Specification API with join on condition returns 2 query instead of 1?
I have a requirement to form a query using JPA as;
select PARENT.ID, PARENT.NAME, CHILD.ID, CHILD.STATUS FROM PARENT
LEFT OUTER JOIN CHILD ON PARENT.ID=CHILD.ID AND CHILD.STATUS in ('Active')
WHERE ...
2
votes
0
answers
22
views
Would upgrading Database Versions change the Exception Call Stack Potentially?
In my code, I was persisting a row of data and had a catch block to throw a (custom) error when a constraint violation was thrown at the DB level. It was a bit messy how I had to get there but it ...
0
votes
0
answers
32
views
Criteria Query JPA with pair wise IN clause
I have this following query.
I need a way to write it using JPA criteria Query.
Select a from alpha a where a.id in (select b.id from beta b where (b.tag_key,b.tag_value) in ((:paramkey1, :paramval1),(...
0
votes
0
answers
23
views
Build warning messages in NetBeans
When I clean and build my project in NetBeans 8.2 I get the following warning message in the Output window. I was hoping to get some advice on how to fix it, anybody had a similar issue that knows how ...
0
votes
0
answers
33
views
jpa embedded composite primary auto generation of ID generating null
I am unable to generate auto increment value for composite primary key id in jpa
i have two entities like
@Entity
@Table
public Class Employee{
@EmbeddedId
private ...
0
votes
0
answers
9
views
Jboss 6.4 - JPA 2.0 Oracle stored procedure
Before I start to explain my issue, I would like to add that I have gone through all question already asked related to my subject but did not found a suitable answer as a solution.
I have a Webservice ...
0
votes
0
answers
16
views
Spring Data JPA separate createOn and updateOn
my auditing works pretty nice but need to change create listener in that way to obtain null values in first update.
@MappedSuperclass
@Getter
@Setter
@ToString
@EntityListeners(AuditingEntityListener....
0
votes
0
answers
18
views
HBM Mapping to Annotation class Conversation
Hi am trying to covert hbm mapping to annotation class and I have encountered a complex mapping
Here is the code :
<class name="Person">
<id name="id" column="...
0
votes
0
answers
45
views
Hibernate cache clearing with JPA2, concurrent threads and a connection pool
In a Spring application using JPA2 with Hibernate, we run multiple tasks in parallel. The tasks each have their own transaction:
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = {...
2
votes
1
answer
52
views
Understanding Relationship Cascading with Merge
Deep diving into Spring JPA and I have troubles to understand whats going on here.
This is the code:
Entity
@Entity
public class PersonP {
@Id @GeneratedValue
private int id;
public ...
0
votes
1
answer
1k
views
Intellij Maven java.lang.IllegalArgumentException: Unsupported class file major version 61 and Entity was compiled with an unsuppported JDK
I am trying to develop an app with a database and i got lots of error like
java.lang.IllegalArgumentException: Unsupported class file major version 61 and [EL Severe]: metadata: 2022-01-26 17:43:20....
0
votes
0
answers
43
views
Hibernate critera query to retrieve entities using join column filter
I want to retrieve records using filter on join column itself. Suppose I have following two entities:
@Entity
@Table(name = "Book")
public class Book {
@Id
@Column(name = "...
0
votes
2
answers
463
views
JPA one-to-one mapping creates an extra column. How to remove it?
I have one-to-one mapping JPA table in my springboot application which works fine.
The Users is the parent table and in the account_no column, it stores the foreign key. Which is, child's primary key. ...
0
votes
0
answers
35
views
JPA specification, select specific column from different entities
I have two entities with OneToMany mapping
@Entity
public class Dealers {
@Id
private String DLR_CD;
private String RGN_CD;
private String CITY_NM;
private int ZIP_CD;
...
0
votes
1
answer
9
views
What is the replacement for EntityManagerFactoryRegistry.getNamedEntityManagerFactory in hibernate 5.x
I was using EntityManagerFactoryRegistry.getNamedEntityManagerFactory from hibernate-entitymanager:4.2.18 but when i update to 5.x i see that this class is no longer available. In fact hibernate-...
0
votes
0
answers
32
views
How to query JPA @ElementCollection map properties
I use JPA (hibernate 5.4.30.Final) to store entities that contain a map with some property values:
@Entity
public class TestEntity
{
@Id
private Long id;
@ElementCollection
@Lob
@...
4
votes
2
answers
381
views
FetchType.LAZY not working for @OneToOne relation
I'm using JPA2 and Springboot2X. Trying to define a simple one-to-one relationship in User and Account tables.
User is the parent while Account is the child. The relationship is from parent to child. ...
0
votes
1
answer
39
views
Why hibernate doesn't create tables automatically even with hibernate.hbm2ddl.auto" value="create"?
I'm trying to force hibernate to create a student table if it doesn't exist, but without success, Hibernate library should be able to do that, but I'm getting an error saying there is no such table in ...
0
votes
2
answers
40
views
JpaRepository query parameters are not getting updated dynamically
Query parameters are not getting updated -
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa....
0
votes
1
answer
34
views
JpaRepsotory custom query method executes but I can see no record updated in database table
I have the updatePassword interface which extends the JpaRepository -
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org....
0
votes
0
answers
32
views
How to add ignore case in JPA for input object?
We can add ignore case like below for normal repository.
@Repository
public interface PassengerRepository extends JpaRepository<Passenger, Long> {
List<Passenger> ...
0
votes
1
answer
247
views
How to specify ignore case in JPA @JoinColumn when I am using two tables entity
I have two entities. Account entity and B_Account.
In Account entity I am joining table like below.
@ManyToOne(fetch=eger)
@JoinColumn(name = "a_type")
private B_Account b_Account;
Now the ...
0
votes
0
answers
33
views
How to refer to a subclass field in a CriteriaQuery with a non entity Superclass
I'm trying to set up a CriteriaQuery predicate for a class ListCodes which is an entity. ListCodes also has a superclass called Auditable which is a MappedSuperClass.
When I try to do this
...
0
votes
1
answer
79
views
JPQL with Group by clause in SQL Server database not working
I am new to SQL Server database. The below JPQL query is not getting executed and not throwing any errors. Just my application hanging over at this query. This code is working fine with MySQL database,...
0
votes
2
answers
66
views
What is the use of the field generator in @GeneratedValue in JPA / Hibernate?
when you create an id like
@Id
@GeneratedValue(generator = "increment")
private Long Id;
what is the role of generator field? what is the meaning of generator?
and should any implementation ...
-1
votes
1
answer
85
views
Column is invalid in the ORDER BY clause with JPA and SQL Server
When I searched this error, found many results, but all are answered are at database (SQL Server) level. But, I am getting this error with JPA query( Simple count query with order clause) and SQL ...
1
vote
0
answers
35
views
How to instantiate a Wrapper Class with more than 7 parameters in Criteria JPA API
I am in situation where i am suppose to select more that 10+ columns from the DB and on these selected fields i am applying logic in and getters. Therefore all these columns are parameters in ...
0
votes
1
answer
75
views
Merge two similar tables using JPA
We have two similar tables with a lot of common columns
Table AA
Id, Name, Active ...
1,A,1
2,null,1
Table BB
Id, Name, Active ...
2,from_B,0
I need to get the AA table, but whenever there is a field ...
1
vote
1
answer
94
views
JPA query, SQRT function not working in ORDER BY clause
I have following JPA query
SELECT p FROM Entity p WHERE p.type = (:type1) AND SQRT((( (:constlong)*(p.longitude - (:long)))*((:constlong)*(p.longitude - (:long)))) + (((:constlat) * (p.latitude - (:...
0
votes
0
answers
55
views
Updating ManyToMany relationship using CriteriaUpdate
I'm trying to update a ManyToMany relationship using CriteriaUpdate.
The following are the entities;
@Entity
@Table(name = "COURSE")
public class Course {
@Id
@GeneratedValue
...
0
votes
1
answer
60
views
some kind of a race condition with JPA and Hibernate updating the same entity
i will explain the situation briefly,
i have 2 entities, parent and child with OneToMany list of child in the parent and ManyToOne reference to the parent from the child. i am cascading all operations ...
0
votes
0
answers
57
views
Custom method for retrieving single entity by the given attribute and value with JPA Criteria Query
I'm trying to write a set of tailored methods for querying a database. I'm new in databases and also not perfectly knowledgeable in Java either. EntityObject is a superclass for all my entity POJOs.
...
0
votes
1
answer
91
views
how to use javax.persistence.Query.executeUpdate() and org.hibernate.session.update() in same transaction
I have an object form class x that I want to update it's properties by session.update() and also a list of objects from class x too that I want to update a property in them using query.executeUpdate() ...
0
votes
0
answers
49
views
How to Model a Join Table in JPA
I'm trying to figure out how to use JPA annotations to map some database tables as Java entities. Class A (Product) has a unidirectional ManyToOne relationship with Class B (Brand). Class B is a child ...
1
vote
0
answers
46
views
JPA Criteria: is it possible to join two queries?
I have a query that is used to order messages by the total number of errors. Every message can have multiple instances. In this case I want to order by the total number of instances which have ...
0
votes
1
answer
80
views
IdentifierGenerationException: attempted to assign id from null one-to-one property + @MapsId + OneToOne bidirectional
I'm getting error
org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property.
The code snippets:
User.java
@Entity
@Table(schema = "public", name =...
0
votes
0
answers
29
views
How to transform SQL "select case when in" to JPQL to get the same result?
My t_user table sample data is like
id name
1 Hunt
2 James
3 Bob
4 Hero
And I use following SQL to get a boolean result, and it works fine as I expected.
SELECT CASE WHEN :userId IN (...
0
votes
3
answers
624
views
java.lang.IllegalArgumentException: Can not set java.lang.Long field com.mypackage.User.id to java.lang.Long
I am using Java 8 with JPA2/Hibernate5 and MySQL.
tables
+--------+ +----------------+ +--------------+
| User | | OrgMember | | Organization |
+--------+ +----------------+...
0
votes
1
answer
77
views
JPA Error a relationship that was not marked cascade PERSIST
I have a table and JPA Entity called State (of a Country) and through JPA, I am trying to write a code for a User (Entity) to register on the website. Clearly, there is a one-to-one relationship ...
0
votes
0
answers
19
views
JPA CriteriaQuery count of rows with value of a column less than given number
I'm looking for the usage of count API of CriteriaQuery to count rows with value of a column less than given number.
SQL : select count(case when threshold_value < 100 then 1 end) from mytable
0
votes
1
answer
151
views
JPA /Hibernate - How to define custom join clause on entity?
I want to join multiple tables to a single column, with additional condition by constant value. Something like this:
@Entity
public class User {
@Id
private String id;
...
}
@Entity
public ...
0
votes
0
answers
60
views
Hibernate 5 not committing/saving records in Oracle DB
Recently migrated my application from Hibernate 3.6.9 to 5.4.10. After that, get methods like criteria.list() is working fine, but when I use session.saveOrUpdate() it is not actually persisting in DB ...
0
votes
1
answer
64
views
Is it necessary to use Entity annotation for Select query records from Database
I have spring boot application with JPA and MySQL. The table is already created and data are present. From the spring boot application, we need to create two API - get a particular record using id and ...
0
votes
1
answer
96
views
How to map enums that share interface to entity's column with JPA?
public interface Base { /* anything */ }
public enum A implements Base { /* anything */ }
public enum B implements Base { /* anything */ }
@Entity
public class Clazz
{
@Column(nullable = false)
...
0
votes
1
answer
358
views
Spring JPA Specification One to Many Join 3 tables
I have 3 entities with the below relationships.
@Table(name = "a")
@Entity
public class A{
@Id
@GeneratedValue
@Column(name = "a_uuid")
@OneToMany(mappedBy = "a&...