I’m using WebSphere 7 (Java EE 5) and OpenJPA 1.2.1. I have a JPA object with a “modifiedTimestamp” attribute, something like this: The related field in the Oracle database is of type DATE. I set the date like so … … and it gets stored, but when I read it back the time of day hasn’t been stored, it allows
Tag: jpa
How to query data out of the box using Spring data JPA by both Sort and Pageable?
I am trying Spring data JPA in my project. I want to know if there is an out-of-the-box API to query data, by both Sort and Pageable. Of course, I know I can write that method myself, I just want to know if there is an out-of-the-box one. My DAO extends JpaRepository, and I found there are the following methods
How to deep copy a Hibernate entity while using a newly generated entity identifier
I’m using a relational DB using a single column pk with a few nested tables. I need to add a simple archiving to my project. The archiving only happens when the application reaches a particular state, so what I was hoping to do was copy my existing hibernate object into a new instance where the new instance would be saved
How to persist @ManyToMany relation – duplicate entry or detached entity
I want to persist my entity with ManyToMany relation. But i have some problem during persisting process. My entities : and Service code : First time, when I try to persist a User with UserRoles “ROLE_USER”, no problem. User and UserRoles and join tables are inserted. My problem is when I try to persist a second User with the same
Problems with making a query when using Enum in entity
I have the following in a Question entity: and I am getting this exception: Exception Description: Error compiling the query [Question.countApproved: SELECT COUNT(q) FROM Question q WHERE q.status = ‘APPROVED’], line 1, column 47: invalid enum equal expression, cannot compare enum value of type [myCompnay.application.Status] with a non enum value of type [java.lang.String]. at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:501) How do I fix this?
Getting old data with JPA
I’m getting old data with JPA, even if I disable the cache. I guess is because the resource is configured to be RESOURCE_LOCAL, but I’m not sure. My code that is getting old info about the user: My entity: Anybody has some idea of what is going on? UPDATE 1 The begin, flush and commit methods were just acts of
JPA: DELETE WHERE does not delete children and throws an exception
I am trying to delete a large number of rows from MOTHER thanks to a JPQL query. The Mother class is defined as follows: As you can see, the Mother class has “children” and when executing the following query: an exception is thrown: Of course, I could first select all the objects I want to delete and retrieve them into
How can I cascade delete a collection which is part of a JPA entity?
In one of my jobs I have the following code: This always fails to delete the entity with the following error: The DELETE statement conflicted with the REFERENCE constraint “FK966F0D9A66DB1E54”. The conflict occurred in database “TFADB”, table “dbo.MonthlyReport_categories”, column ‘MonthlyReport_id’. How can I specify the mapping so the elements from the categories collection get deleted when the report is deleted?
JPA: unidirectional many-to-one and cascading delete
Say I have a unidirectional @ManyToOne relationship like the following: If I have a parent P and children C1…Cn referencing back to P, is there a clean and pretty way in JPA to automatically remove the children C1…Cn when P is removed (i.e. entityManager.remove(P))? What I’m looking for is a functionality similar to ON DELETE CASCADE in SQL. Answer Relationships
How to properly determine whether an “exists” JPA Criteria Query clause returned true or false?
I don’t know how to perform a JPA criteria query that returns with a boolean output. The goal is to have a criteria query that looks like this when rendered on Oracle: The where exists (…) part I performed with a subquery. I’m struggling with the external query. The practical use of this is to determine whether that subquery in