jpa

JPA QL, How to NOT select something

Hi. I have a pretty simple sql I need to perform. I have a ProcessUser, Role and a ProcessUserRole table. A straight forward many-to-many I want to select all ProcessUser's that does also have a Role of admin. However my jpa sql fails because my user also has role officer, so it is retrieved in the list. Here is the sql: entityMana...

Two EntityManagerFactories...

I want to have two EntityManagerFactories (org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in this case), with each of them having their own data source and own set of persistent objects. So somehow I need to be able to scope entities to a particular entity manager factory. I would prefer not to have to hard code the ...

Why in JPA EntityManager queries throw NoResultException but find does not?

Can somebody tell me the intrinsic reasons why in the JPA 1.0 EntityManager when retrieving an Object via find, you have to deal with null if not found, but when using the Query interface via createQuery getResultList throws a NoResultException when not found. Maybe i am missing something but I feel its very inconsistent for a Language,...

Spring @Transactional merge and persist question

Hi, new to Spring and here @stackoverflow I'm building an stand-alone Inventory & Sales tracking app (Apache Pivot/Spring/JPA/Hibernate/MySQL) for a distributor business. So far I think everything is CRUD, so I plan to have a base class with everything @Transactional. Then I got a problem with my save generic method. Does persist and ...

JPA one-to-many relationship question (relations on one entity)

In this JPA example there is a code: @OneToOne(cascade=CascadeType.ALL) private Deity mother; @OneToOne(cascade=CascadeType.ALL) private Deity father; @OneToMany(cascade=CascadeType.ALL) private Set<Deity> children; Why relation with father and mother is implemented by @OneToOne annotation and not in @ManyToOne relation? If Child an...

programatically make all relationships CascadeType.MERGE

We have strictly defined which relationships are CascadeType.MERGE in our app. This plays into our version checking (optimistic locking). So, our CascadeType definitions sometimes have MERGE and sometimes not. This is all great for our OLTP application. However, we also have a requirement to load in data (fine to do it batch offline)...

java.util.ConcurrentModificationException on CollectionOfElements

Hi. I seem to get a ConcurrentModificationException when I have a CollectionOfElements inside an Embedabble. If would like to have it like that, however If I change Route from Embedabble's to Entity than everything works fine. I have even tried adding @Version, but that doesn't seem to work. Here are a snippet of my classes. Kart.java:...

Issue Using Hibernate Criteria object with composite key

NOTE: I have changed the details provided due to comments provided. The new technical details are actually code that I am trying to run currently. I have a weird problem going on currently with one of my OneToMany / ManyToOne bidirectional relationships. In the parent table I have a long which is the identifier and the child also h...

in toplink and struts 2 based application, even after commiting data data disappears from the database

I have a struts 2 application and a toplink persistence provider running on tomcat 6.0.20 and a MySql 5.1.38 server on a GNU/Linux machine. After committing the data the when i go to retrieve it the data it has disappeared from the database. I do a em.commit() and em.flush() after my queries have executed. How do they disappear? I am u...

Deleting Objects with JPA with Foreign Key Constraints

I have a two classes, Service and Customer, with a many-to-one association from Service to Customer. I want to delete a Customer and any Service that references it. I'm using JPA as the ORM (with Hibernate underneath) attached to a PostgreSQL db. It'd be great if I could define the association in such a way that deleting the Customer wo...

When to use EntityManager.find() vs EntityManager.getReference()

I have come across a situation (which I think is weird but is possibly quite normal) where I use the EntityManager.getReference(LObj.getClass(), LObj.getId()) to get a database entity and then pass the returned object to be persisted in another table. So basically the flow was like this: class TFacade{ createT(FObj, AObj) { T T...

Tool to Execute JPQL Queries?

Is there any sort of tool available which allows one to execute JPQL queries against a database "directly"? I would like to type JPQL queries directly into a window and execute them. Of course it would probably require me to do quite a bit of configuration so that it would be aware of my JPA entities, etc., but I guess it could be done...

How can I configure a Servlet in Eclipse to use a JPA project?

I am using Eclipse Galileo and I wanted to deploy a simple application, using JPA, GlassFish 2.1 and MySQL 5. Unfortunately, I could not find any tutorials for GlassFish 2.1 (just for 3.0, but I cannot use it). I created a JPA project, added a MySQL5 connection and generated an Entity from the database. The generate JPA class is: pac...

JPA custom script at startup

What is the best way to fill tables create with jpa at application startup/shutdown of application ? like but with data manipulation language instead data definition language. i'm using HibernatePersistence as persistence provider. ...

Trouble with Aspectj load-time-weaving when using EclipseLink JPA in Spring dm Server 1.x

I am attempting to get EclipseLink JPA working inside the Spring dm Server OSGi environment. Relevant frameworks and libraries downloaded from the Spring Enterprise Bundle Repository include: dm Server 1.0.2.SR02 AspectJ Runtime 1.6.3 AspectJ Weaver 1.6.3 Spring Framework 2.5.6.A Eclipse Persistence 1.1.0 Javax Persistence API 1.99.0...

How do you create a DAO class for Seam / JPA (hibernate)?

Hi, I'm learning Seam and JPA/Hibernate and while I could find some examples on how to build a DAO class with Hibernate I'm a bit confused on how to do the same thing with Seam (or even if that is at all necessary). I do know that seam manages the transactions using its conversations so I don't (?) have to worry about committing / roll...

JPA Annotations in Android

Hello, We have a project that uses JPA/Hibernate on the server side, the mapped entity classes are in their own Library-Project and use Annotations to be mapped to the database. I want to use these classes in an Android-Project - is there any way to ignore the annotations within Android, to use these classes as standard POJOs? ...

Problem selecting the value from a JComboBox binded to a list

I have a JComboBox binded to an observable list (result of a jpa query) in a java desktop application. It gets all the values from that list and displays them correctly, but I'm not able to select any particular value from the dropdown: that is, when I click on the widget the list of options gets displayed correctly, when I click on an i...

sync entitymanager from database

Hi. i have a swing desktop application that use a entitymanagerfactory, but when this application is executed many times at the same time, the diferents entity managers have old data that was modified by others and this changes will not visible until the next entitymanagerfactory... how can i sync in anytime the entitymanager with the da...

Example of using CURRENT_DATE in JPA query

Can anyone point me to an example on how to use CURRENT_DATE in a JPA query? CURRENT_DATE is specified in JPA but I haven't been able to make it work. I always get the unexpected token [CURRENT_DATE] exception. Since is specified in JPA all providers should comply with it right? I'm using EclipseLink 2.0 BTW. ...