entitymanager

Fixing Null EntityManger in Spring MVC application?

我是研究僧i 提交于 2019-12-17 18:29:47
问题 In the following code I am trouble with my injected EnitityManager, which always shows up as null ; public class GenericController extends AbstractController { @PersistenceContext(unitName = "GenericPU") private EntityManager em; protected ModelAndView handleRequestInternal( HttpServletRequest request, HttpServletResponse response) throws Exception { //(em == null) is always trigged if (em == null) throw new NullPointerException("em is null"); Collection<Generic> Generics = em

JAVA: an EntityManager object in a multithread environment

霸气de小男生 提交于 2019-12-17 17:32:06
问题 if I have multiple threads, each use injector to get the EntityManager object, each use the em object to select a list of other class objects. Ready to be used in a for loop. If a thread finishes first and calls clear(), will that affect the other threads? Like the for loop will have exception? How about close()? If the answer is "It depends", what (class definition? method call?) and where (java code? annotation? xml?) should I look at to find out how is it depended? I did not write the

How to call Entity Manager in a constructor?

筅森魡賤 提交于 2019-12-17 16:27:45
问题 I've been trying to call Entity Manager in a constructor: function __construct() { $this->getDoctrine()->getEntityManager(); ... but, as I've seen in this answer: Stackoverflow question, it can't be done. So I wonder if there is a way to achieve it, as I have to call it often, and want to do some stuff in the constructor after getting the repository. Edit: I've tried with @MKhalidJunaid answer: //src/MSD/HomeBundle/Resources/config/services.yml services: imageTransController.custom.service:

Create JPA EntityManager without persistence.xml configuration file

馋奶兔 提交于 2019-12-17 03:46:21
问题 Is there a way to initialize the EntityManager without a persistence unit defined? Can you give all the required properties to create an entity manager? I need to create the EntityManager from the user's specified values at runtime. Updating the persistence.xml and recompiling is not an option. Any idea on how to do this is more than welcomed! 回答1: Is there a way to initialize the EntityManager without a persistence unit defined? You should define at least one persistence unit in the

Unexpected detached entities with extended persistent context

蓝咒 提交于 2019-12-13 13:37:13
问题 I'm trying to maintain state across multiple calls by using an EXTENDED_PERSISTENT_CONTEXT. My understanding is that managed entities will not detach between calls however I keep getting errors related to detached entities in calls after I have previously thrown validation errors. The state is being maintained in a stateful session bean: @Named(SessionFacadeBean.SEAM_NAME) @SessionScoped @Stateful @LocalBean @AccessTimeout(value = 10, unit = TimeUnit.SECONDS) public class SessionFacadeBean

.java terms and random words clarification

拟墨画扇 提交于 2019-12-13 04:44:13
问题 Im really new to java, jsf, jsp, and I need to learn how it works quickly. So the website Im using to practise has some terms etc that I dont know what they mean and Im hoping somebody can explain what they mean and how/what they are used for:) Requestscoped Applicationscoped Sessionscoped EntityManager and could someone walk me through what these lines do? @RequestScoped public class Dao { @DataRepository @Inject private EntityManager entityManager; 回答1: First of all, in Java (5 and higher),

How to use OpenJPA EntityManagerFactory in JSF

坚强是说给别人听的谎言 提交于 2019-12-13 04:23:30
问题 I use OpenJPA on WebSphere Application Server. My WebApplication uses JSF 2 (without EJB). I wanted to know if there are best practices how to use JPA in JSF. I found that the EntityManagerFactory (EMF) should be application scoped. Also the EMF should be (only) destroyed when the application stops. But my sources are not the newest: Java Notepad: JPA EMF in web applications from 2007 Best way to use JPA in web-tier from 2010 How to close a JPA EntityManger in web applications from 2007 Are

JPA - strange behavior using EntityManager remove() method

蹲街弑〆低调 提交于 2019-12-13 04:16:28
问题 I am in a configuration (JTA - CMT) in which I have to remove an entity object after creating it. I use em.remove(object) after finding it, but remove doesn't work, or it seems to be not working. What happens is that the object I want and try, to remove is still in DB. Once the removal operation is performed, if I later try to retrieve the records from the entity table it belongs to, I GET THIS OBJECT (obviously with the other objects I previously saved). My check into the entity table,

EntiyManager CreateQuery Hangs

做~自己de王妃 提交于 2019-12-13 03:58:57
问题 I am creating a webapp with EclipseLink for the persistence layer, and I have a DAO that is hanging when I attempt to load an object. The application/code has previously worked when loaded in to other machines/IDEs, but I have just loaded it into Eclipse Indigo on a Windows 7 machine and this error has started occuring (there are no compile errors/warnings in the code etc, and the app builds/starts fine). The DAO method is as follows: public Account loadAccountByUserName(String userName) {

Java EntityManager null with @PersistenceContext

元气小坏坏 提交于 2019-12-13 03:51:01
问题 I'm using Wildfly 10, Jersey, and injecting dependencies with @Inject. I have DAO and Service interfaces with their implementations declared in a CustomBinder. The injections work well, but the EntityManager is injected null with the @PersistenceContext annotation. I'm using MySQL and the datasource test-connection is working. API Rest class @Path("/account") public class CuentaServiceRS { @Inject private ICuentaService cuentaService; @GET @Produces(MediaType.APPLICATION_JSON) public Cuenta