entitymanager

EntityManager is always NULL using SpringFramework

久未见 提交于 2019-12-24 18:09:11
问题 Good day, I've been currently working on a Maven + Spring + Hibernate project. Actually, this is just a test project just to get familiar on how Spring works with Hibernate (+Maven). I've already setup and prepare the necessary dependencies. i.e. the appcontext.xml for Spring, the persistence.xml for Hibernate, the entity and DAO objects for JPA/Persistence/Hibernate. During debug, it's observed that the EntityManager is always null . I don't know what's causing this because I've done the ff:

EntityManagerFactory not being injected using @PersistenceUnit

送分小仙女□ 提交于 2019-12-24 16:25:02
问题 I'm a java beginner. I'm in trouble to configure a persistance unit using JTA transactions. I need to use a PostgreSQL database that is already defined, configured and populated. Using netbeans, i created the persistance.xml and glassfish-resources.xml as fallows: <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence

How can use JPA with play 2.5 without creating a entitymanager factory for each of my different calls?

本秂侑毒 提交于 2019-12-24 15:57:47
问题 I'm working on a API with play 2.5 for an Oracle database. Now I'm trying to use the build in features for JPA in play. On this moment I get the error "No EntityManager bound to this thread. Try wrapping this call in JPAApi.withTransaction, or ensure that the HTTP context is setup on this thread." . This is the code that's responsible for the actual call. package actors.protocols; import akka.japi.Option; import model.DTO.AanleverAfspraakVO; import model.domain.AanleverAfspraakDO; import play

Mocking EntityManager

余生长醉 提交于 2019-12-24 14:41:55
问题 I am getting NPE while mocking EntityManager, below is my code, @Stateless public class NodeChangeDeltaQueryBean implements NodeChangeDeltaQueryLocal { @PersistenceContext private EntityManager em; @Override public String findIdByNaturalKey(final String replicationDomain, final int sourceNodeIndex, final int nodeChangeNumber) { List<String> result = NodeChangeDelta.findIdByNaturalKey(this.em, replicationDomain, sourceNodeIndex, nodeChangeNumber).getResultList(); return result.isEmpty() ? null

Field values are not being modified on PreUpdate callback

故事扮演 提交于 2019-12-24 12:34:09
问题 I've defined the following class as as default Entity Listener, so every time I call the persist() or merge() methods this code will be executed automatically: public class StringProcessorListener { @PrePersist @PreUpdate public void formatStrings(Object object) { try { for (Field f : object.getClass().getDeclaredFields()) { if (f.getType().equals(String.class)) { f.setAccessible(true); if (f.get(object) != null) { f.set(object, f.get(object).toString().toUpperCase()); } } } } catch

Multiple EntityManagers managed by the container (CMT)

心不动则不痛 提交于 2019-12-24 02:20:13
问题 I have the following situation: My applications needs to dynamically connect to multiple databases, so after a lot of search I think the best option is to do create multiple EntityManagers and decide at runtime which one to use. Here is the code: public class GenericDao { @PersistenceContext(unitName = "db1") protected EntityManager em1; @PersistenceContext(unitName = "db2") protected EntityManager em2; @PersistenceContext(unitName = "db3") protected EntityManager em3; } This way I can

Can I have an entity that only maps to some columns of a table?

主宰稳场 提交于 2019-12-24 02:05:31
问题 I'm making a database migration tool and am dealing with a source database that's very unwieldy. It's basically one giant table that has upwards of 40-50 columns. However not all of these columns are useful to me. I only want maybe a dozen or so of them. Once I get that data I'm making requests to a web service that will handle everything on the destination end of migration. My options are basically creating queries manually to only select the columns I want, or make an Entity that maps the

How does Spring-JPA EntityManager handle “broken” connections?

江枫思渺然 提交于 2019-12-24 00:45:04
问题 I have an application that uses a Spring-EntityManager (JPA) and I wonder what happens if the database happens to be unavailable during the lifetime of my aforesaid application. I expect in that situation it will throw an exception the first time to do anything on the database, right? But, say I wait 10 minutes and try again then and the DB happens to be back. Will it recover? Can I arrange it so it does? Thanks 回答1: Actually, neither Spring nor JPA have anything to do with it. Internally all

Hibernate Entity manager auto flush before query and commit changes to DB in transaction

淺唱寂寞╮ 提交于 2019-12-23 18:21:06
问题 I am using Hibernate 3.6.0 with JPA 2 on Jboss AS 6.0.0 final. In an EJB of mine, there's a method which updated entity values and do some query on it. The whole method is running in a BMT transaction. If anything fails, all changes should be rollback and not committed to DB. The Database is mySql. Before running JPA query, JPA will auto flush the changed states to DB to prevent any stale data from returning. However, within my method, the auto-flush directly update and commits the changes to

Two entity managers in Spring

∥☆過路亽.° 提交于 2019-12-23 12:49:12
问题 I had done this programmatically at some point - that is creating two entity managers with different data sources and providing them for different services. However now I am building a webApp using Spring. Thing is that I want to have two entity managers responsible for separate databases. So in my case, half of DAO's would be using emNumber1 , and second half would be using emNumber2 . Oh and totally different persistence units as I only need to read data from DB1 and then process it and