entitymanager

Exception not cuaght with Entity Manager

假如想象 提交于 2019-12-02 10:23:38
I have an Entity Manager in my EJB @PersistenceContext(unitName = "cnsbEntities") private EntityManager em; I populate an object and then I commit it in my DB, but if I have an exception, for duplicate ID, I can't catch it and I don't know why. try{ em.merge(boelLog); } catch (Exception e){ System.out.println("Generic Exception"); } JPA uses transactions to send entity modifications to the database. You can specify those transactions manually through Bean Managed Transactions (BMT) or let the application server do it for you (Container Managed Transactions; the default). So, you need to catch

Websphere 7 EntityManagerFactory creation problem

柔情痞子 提交于 2019-12-02 09:58:31
问题 I'm working on a maven project which uses seam 2.2.0, hibernate 3.5.0-CR-2 as JPA provider, DB2 as database server and Websphere 7 as application server. Now I'm facing de following problem: In my EJBs that are seen also as SEAM components I want to use the EntityManager from EJB container (@PersistenceContext private EntityManager em) not Seam's EntityManager (@In private EntityManager em). But this is the problem, I cannot obtain an EntityManager using @PersistenceContext. On server logs it

Add a namespace to an already configured EntityManager

随声附和 提交于 2019-12-02 07:49:33
问题 I've got an EntityManager instance fully configured and working. The question is how to add an additional namespace to this EM? $em->getConfiguration()->addEntityNamespace('MyGreatBundle', 'My\GreatBundle\Entity'); This does not work, throws the following: Doctrine\Common\Persistence\Mapping\MappingException: The class 'My\GreatBundle\Entity\User' was not found in the chain configured namespaces 回答1: I managed to fix this issue, had to add the driver too: $namespace = 'My\GreatBundle\Entity';

Websphere 7 EntityManagerFactory creation problem

爷,独闯天下 提交于 2019-12-02 04:49:30
I'm working on a maven project which uses seam 2.2.0, hibernate 3.5.0-CR-2 as JPA provider, DB2 as database server and Websphere 7 as application server. Now I'm facing de following problem: In my EJBs that are seen also as SEAM components I want to use the EntityManager from EJB container (@PersistenceContext private EntityManager em) not Seam's EntityManager (@In private EntityManager em). But this is the problem, I cannot obtain an EntityManager using @PersistenceContext. On server logs it sais that it cannot create an EntityManagerFactory and gets a ClassCastException: java.lang

JPA EntityManager.detach() still load lazy relations

女生的网名这么多〃 提交于 2019-12-02 04:20:11
问题 I got a problem that goes against my understanding of how it supposed to work. I have a Arquillian-test that tests a repository-method with a JPA query. The test persists an object, and then persists an another object with the first persisted object in a field. Then it calls the repository-method. Next the test detaches (and clear the entitymanager, checks that the object is not contained in the em etc etc). Last the test checks if the related object is there or not (it shouldn't since the

Spring + JPA + Hibernate

半城伤御伤魂 提交于 2019-12-02 00:43:54
问题 I am newbie in Spring. I am trying to setup simple web application with Spring 3.1.3 and JPA 2.0 I have added all necessary libs to the WEB-INF/lib. There is no errors during the startup but entityManager in my DaoImpl file is null. So, this is my configuration: persistance.xml <?xml version="1.0" encoding="UTF-8"?> <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

Spring + JPA + Hibernate

霸气de小男生 提交于 2019-12-01 20:46:14
I am newbie in Spring. I am trying to setup simple web application with Spring 3.1.3 and JPA 2.0 I have added all necessary libs to the WEB-INF/lib. There is no errors during the startup but entityManager in my DaoImpl file is null. So, this is my configuration: persistance.xml <?xml version="1.0" encoding="UTF-8"?> <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/persistence_2_0.xsd"> <persistence-unit name="fcmsServer

LazyInitializationException with CDI Managed Bean and Stateful Session Bean

不羁的心 提交于 2019-12-01 19:36:50
I have a CDI Managed Bean (a bean annotated with @Named that is used on JSF) that has a Stateful Session Bean injected. This session bean is like a service, it has the entity manager (annotated with @PersistenceContext(type= PersistenceContextType.EXTENDED)) and expose come methods to manipulate some entities. Those entities are on the managed bean, who is ConversationScoped. Then, the JSF calls a method of the managed bean and the managed bean calls some method of the "service" (the stateful session bean). I don't know if this is the best design, but it was working well. But there's an Entity

How to use entityManager inside Entity?

眉间皱痕 提交于 2019-12-01 18:43:07
I have this function in Entity class but the getDoctrine do not fond... public function getObject() { $em = $this->getDoctrine()->getEntityManager(); switch($this->objectType) { case 'video': return $em->getRepository('fdj2012AdminBundle:Video')->find($this->objectId); break; case 'default': return false; break; } } How to use entityManager inside my Entity ? Actually Entity shouldn't know about EM. I use Event Listeners if I need advance logic in my Entity. When you register Listeners like services you can pass args there, like a EM or Container and get them inside Listener class. Symfony Doc

Entity Manager not working in JavaFX

隐身守侯 提交于 2019-12-01 13:57:12
I'm using Persistence unit and Entity classes from Database, all in a JavaFx fxml Application, I succeeded importing all my tables as entities in my Model, the proble is that I get an exceptions and errors when I try to insert into an entity, here's my entire code public class SampleController implements Initializable { @PersistenceContext(unitName="RawdaPU") private EntityManager em; @FXML private Label label; @FXML private void handleButtonAction(ActionEvent event) { Moyendidactique moyenDidactique = new Moyendidactique("1", "moyen1", "Type1"); em.persist(moyenDidactique); em.close(); }