jpa

Best way to share Java implementation between concrete JPA classes?

I have about 10 different entities in my J2EE application that right now share the exact same implementation. They all inherit from the same generic abstract class that has been annotated as a @MappedSuperclass, but this class contains none of the implementation I have repeated in all the concrete subclasses. If I could, I'd put all...

How to map custom collection in JPA?

Hello everybody! I have problems in mapping custom collection with JPA (Hiberante provider). For example when I am using object with attribute List<Match> matches; with <one-to-many name="matches"> <cascade> <cascade-all /> </cascade> </one-to-many> in my ORM file, it is allright; But if I replace "List matches;" ...

Spring JPA - Injecting transaction manger vs injecting entity manager

If I wanted manage transactions programmatically, what is the difference between starting the transaction by injecting a PlatformTransactionManager vs directly injecting EntityMangerFactory/EntityManager and getting transaction from Entitymanager public class MyDAO { @PersistenceContext(unitName="test") EntityManager em; JpaTransactio...

Hibernate+Oracle+Clob: Content of attributes get switched.

Has anyone heard of this error before: I have a Java 5 application, that uses Hibernate 3.3.2 to access an Oracle Database 10g, the JDBC driver is the Oracle light driver version 10.2.0.4.0 (the most recent version, I think). The database access happens during a transaction that is managed via the AOP-tools of spring. There is one datab...

EclipseLink: Query to MappedSuperclass fails

My application is a store selling fishes, aquariums etc. I want to get a list of top 10 items among all the items based on sales count. I use the following class: @MappedSuperclass @NamedQueries({ @NamedQuery(name="getTopItems",query="SELECT x FROM FishStoreItem x ORDER BY x.salescnt DESC, x.title DESC") }) public abstract class Fis...

JPA entity for a table without primary key

I have a MySQL table without primary key, and I have to map it into a JPA entity. I cannot modify the table in any way. Because entities must have a primary key, I have to specify one. If I'm certain that the field I use as a primary key in the entity (or the fields, should I opt for using composite primary key) will always be unique (a...

Two db connections using ejb, java persistence entitymanager

I am am tryign to access two dbs via one slsb, specifically one method within an slsb. However this is not possible ? Other than altering the stored procs is there anything else I could do ? @PersistenceContext(unitName = "DB1") private EntityManager oneEntityManager; @PersistenceContext(unitName = "DB2") private EntityManager twoEnt...

Call Oracle Stored Procedure Using createNativeQuery

I need to call a stored procedure using JPA and found this article: http://www.oracle.com/technology/pub/articles/vasiliev-jpql.html which explains how to use EntityManager.createNativeQuery. However, the example actually calls a function that has a return argument. I've tried searching for an example of calling a stored procedure th...

JPA Collection of Embeddables

I'm trying to persist a collection of embeddable/serializable objects as one of the fields in my entity. I've seen the trick where you wrap the list in another serializable class and store the whole thing as a lob, but that feels like a hack. As far as I can tell, the jpa way to do this is with an @ElementCollection(targetClass=BlaBlaB...

Hibernate not JPA compliant regarding @Access?

According to my JPA 2.0 book (and online documentation), I should be able to mix field and property access within a single entity or entity hierarchy. The annotation of @Access on the class specifies the default access. When placed on a field or property getter @Access can specify that the default should be overridden for this field. ...

Easy way to save basic auditing data on domain objects?

My application uses large trees of domain objects and for most of these objects I'd like to persist some basic information (updatedby, modified time, etc.). I have already added these properties & columns to my application. I was about to code the setting of these values in all the various constructors, etc. when it occurred to me tha...

Websphere: JPA: java.lang.IllegalArgumentException: Object: Entity is not a known entity type.

I'm trying to deploy an app using Eclipselink as my JPA Layer on IBM Websphere 7.0.0.9. While trying to do any CRUD operations, i get the following exception: Caused by: java.lang.IllegalArgumentException: Object: Entity is not a known entity type. at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist...

Bypass GeneratedValue in Hibernate (merge data not in db?)

My problem is the same as described in [1] or [2]. I need to manually set a by default auto-generated value (why? importing old data). As described in [1] using Hibernate's entity = em.merge(entity) will do the trick. Unfortunately for me it does not. I neither get an error nor any other warning. The entity is just not going to appear i...

How to cascade persist using JPA/EclipseLink

I am having problems performing a cascade persist operation on a parent entity. When the child entity is persisted, the reference (generated id) to the parent entity is null. How would I get this to persist correctly? Thanks, RG Entities: @Entity public class Contact { @Id @GeneratedValue(strategy=GenerationType.TABLE, gen...

Problem on JPA: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

Hey there everyone ... I´m using JPA with SPRING and mySQL and I´m having problems while removing an entity... I am doing this: @PersistenceContext private EntityManager em; ... @Transactional public void delete(Long id) { em.flush(); OwnerEntity e = em.getReference(Entity.class, Long.valueOf(id)); if (e == null) throw new Ex...

Retrieving Polymorphic Hibernate Objects Using a Criteria Query

In my model I have an abstract "User" class, and multiple subclasses such as Applicant, HiringManager, and Interviewer. They are in a single table, and I have a single DAO to manage them all. User: @Entity @Table(name="User") @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn( name="role", discriminatorTy...

Refreshing collection (getResultList) of entities bu entityManager.refresh

Hi everybody, How to refresh getResultList collection of entities when JPA cache is enabled. I mean: List customers = query.getResultList(); ????? > em.refresh ( customers ) ! // i need refresh because the cache is enabled. RGDS Navid ...

JPA - transactions not being commited

Hey guys, i'm working on a project in which i use JPA, Hibernate and all this stuff for the first time and i ran into problem with transactions not being commited. I use class User which looks like this: package org.tomasherman.JBTBackup.Resource.Entity; import javax.persistence.*; import java.io.Serializable; @Entity @Table(name ...

JPA - EclipseLink - How to change default schema

I'm programming a web application using weblogic and oracle. the datasource is configured through JNDI, with a restricted database user who can DML into tables, but can't DDL. As you may guess, that user isn't the owner of those tables, but he's granted access. Let's say he is GUEST_USER The application is using JPA + EclipseLink, and ...

jpa merge not working

I have a problem with merging of objects using JPA. My code goes like this. EntityTransaction entr = em.getTransaction(); entr.begin(); Query q = em .createQuery("SELECT filterName FROM IbFilterName filterName where" + " filterName.filterId = 42352 "); List<IbFilterName> filterNameList = q.getResultList(); for(IbFilterName fil...