JPA transient information lost on create

This is, more or less, working as designed. The semantics of transient are precisely that the data is not persisted. The entity returned from entityManager.merge(obj) is, in fact, an entirely new entity that maintains the state of the object passed into merge (state, in this context, being anything that is not part of the persistent … Read more

JPA 2.0 native query results as map

Which JPA are you using – Hibernate, EclipseLink or something else? There is no standard way to do this in JPA but your specific implementation may allow it – for example, Eclipselink has a query result type hint. http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg03013.html Query query = entityManager.createNativeQuery(sql); query.setHint(QueryHints.RESULT_TYPE, ResultType.Map); For Hibernate, with javax.persistence.Query dbQuery: org.hibernate.Query hibernateQuery =((org.hibernate.jpa.HibernateQuery)dbQuery) .getHibernateQuery(); hibernateQuery.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE);

Spring batch jpaPagingItemReader why some rows are not read?

org.springframework.batch.item.database.JpaPagingItemReader creates is own entityManager instance (from org.springframework.batch.item.database.JpaPagingItemReader#doOpen) : entityManager = entityManagerFactory.createEntityManager(jpaPropertyMap); If you are within a transaction, as it seems to be, reader entities are not detached (from org.springframework.batch.item.database.JpaPagingItemReader#doReadPage): if (!transacted) { List<T> queryResult = query.getResultList(); for (T entity : queryResult) { entityManager.detach(entity); results.add(entity); }//end if } else { results.addAll(query.getResultList()); tx.commit(); } For this … Read more

Create JPA EntityManager without persistence.xml configuration file

Is there a way to initialize the EntityManager without a persistence unit defined? You should define at least one persistence unit in the persistence.xml deployment descriptor. Can you give all the required properties to create an Entitymanager? The name attribute is required. The other attributes and elements are optional. (JPA specification). So this should be … Read more