EntityManager « EntityManager « JPA Q&A





1. Can you access EntityManagers from EntityListeners?    stackoverflow.com

I'm aware that JSR-000220 Enterprise JavaBeans 3.0 Final Release (persistence) spec states: "In general, portable applications should not invoke EntityManager or Query operations, access other entity instances, or modify relationships in a lifecycle ...

2. Does Hibernate EntityManager include Core?    stackoverflow.com

I'm using Hibernate's implementation of JPA. My Maven pom.xml references hibernate-entitymanager. My question is, does Hibernate EntityManager (called "Standard Java Persistence API for Java SE and Java EE" on Hibernate's home ...

3. how do i pass EntityManager to @PostUpdate    stackoverflow.com

I want to save history of changes, so in @PostUpdate i want to create new instance of another entity and save it, how do i pass EntityManager to that method?

4. JPA EntityManager, how does it work?    stackoverflow.com

Sorry for the noob question, but I'm having problems with JPA+Hibernate so I thought that something is not clear in my mind. I have some entities, say A, B, C, D ...

5. Why does hibernate-entitymanager-3.3.2.GA depend on hibernate-3.2.6.ga?    stackoverflow.com

In my Maven pom.xml I have the following dependencies:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>3.3.2.GA</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
   ...

6. EntityManager initialization best practices    stackoverflow.com

When using EntityManager, is it better to get one instance with PersistenceContext and pass it around in my program, or should I use dependency injection more than once? In my application each ...

7. Java - JPA - When we need more than one EntityManager?    stackoverflow.com

I am learning JPA and have one question: In which situations we need more than one EntityManager in our application? The two situations that I am aware of are as follows:

  • When our application ...

8. JPA2 -- Where is EntityManager.detach?    stackoverflow.com

I read in several places that JPA2 will support a detach method call on Entity Manager. I am running with Hibernate 3.5.1-FINAL and Spring 3.0.2-RELEASE as Maven dependencies -- snagged ...

9. JPA2 + Hibernate + Order By    stackoverflow.com

Is it possible (using Hibernate and JPA2 Criteria Builder [1]) to order by a method's result rather than an entity's member?

public class X {
    protected X() {}
  ...





10. Hibernate EntityManagerFactory EntityManager    stackoverflow.com

Can I create an EntityManager from EntityManagerFactory outside a bean. If so, how would I do it?

11. Keeping JPA EntityManager open?    stackoverflow.com

I am learning JPA and the general pattern in examples seems to be as follows:

EntityManager em = factory.createEntityManager();
em.getTransaction().begin();
// ....
em.getTransaction().commit();
em.close();
Now I am wondering why do we continually create and close EntityManagers, as ...

12. Any drawbacks of using Hibernate EntityManager (vs. Hibernate Core)?    stackoverflow.com

The Hibernate EntityManager documentation states, that:

You may use a combination of all three together, annotations without JPA programming interfaces and lifecycle, or even pure ...

13. How frequently should I create an EntityManager?    stackoverflow.com

I have an EntityManagerFactory for which I can create one (or multiple) EntityManager instances. I'm using a Servlet environment, and I've got one EntityManagerFactory wired up to the servlet (via the ...

14. How do you create an EntityManager when you are unsure of the unit name?    stackoverflow.com

I'm in a situation where I need to determine the EntityManager's unit name at run time. For example, I'd like to do something like this:

@PersistenceContext(unitName = findAppropriateJdbcName())
EntityManager entityManager;
However, this is not possible ...

15. How to mock EntityManager?    stackoverflow.com

I need to mock entity-manager to make testing service layer (in my case a session facade) to be independent of the underlying layer (which in my case is the entity-manager). So how ...

16. cannot run hibernate with EntityManager    stackoverflow.com

I am trying to run a simple hello world program as given in "Java Persistence with Hibernate" book by Cristian Bauer & Gavin King. Only change I made was to change ...





17. jpa entitymanager contains always returns false    stackoverflow.com

I have a simple test case where I save an object and then test if the object is present in db. but the contains method always returns false. The object is ...

18. EntityManager can't see mapped classes in jar file    stackoverflow.com

I have a set of annotated entity classes that live in a common.jar file. I'm able to build a .war file which references this common.jar, and to generate ddl via hbm2ddl. ...

19. is request scope entitymanager required/useful for Sprnigmvc, struts apps    stackoverflow.com

Recently came across Request Scoped EntityManager in a wicket application. Just curious as to weather this sort of a thing is needed at all and if so, then does it apply ...

20. Is hibernate-entitymanager.jar required for Hibernate 3.5 version    stackoverflow.com

I am trying to install Hibernate 3.5 jar files in my application. The documentation says hibernate3.jar and hibernate-jpa-2.0-api-1.0.0.Final.jar are suffice. But when I start my ...

21. Is it necessary to always exclude cglib when using hibernate-entitymanager?    stackoverflow.com

Wasted a lot of time configuring my project and finally find out that I have to exclude cglib from my dependencies:

<dependencies>
    <dependency>
       ...

22. JPA: A question about entityManager.joinTransaction    stackoverflow.com

Let say we declare a application-managed entity manager like following (a similar version can be found at: http://download.oracle.com/docs/cd/E19798-01/821-1841/bnbqy/index.html):

@PersistenceUnit EntityManagerFactory emf;
@Resource UserTransaction utx;
protected void doPost(HttpServletRquest req,...)
   em ...

23. Force 'reload' of JPA EntityManager in integration test    stackoverflow.com

In a Spring-enabled integration test, I need to force the EntityManager to re-read from the database.

@Test
@DataSet("/xml/dbunit/truncate-tables.xml")
public void createTerminalFromQuery() {

    // there should be zero terminals in the empty ...

24. Entity Manager Management    stackoverflow.com

How does an entity manager manage? I was reading a couple of articles
http://codeidol.com/java/netbeans/Persistence-EntityManager/Interacting-with-an-EntityManager/ I came across a couple of questions to ask! After using

Customer cust = entityManager.find(Customer.class, 2);
If we in fact ...

25. EntityManager.unwrap() throws java.lang.AbstractMethodError    stackoverflow.com

I'm having some issues implementing JPA 2.0 in my app. I'm using Criteria queries and I need to grab the session from the EntityManager. I do it in the following way ...

26. create EntityManager from EntityManagerFactory    stackoverflow.com

I am trying to get an instance of jpa EntityManager in a servlet as follows

ApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
EntityManagerFactory emf = (EntityManagerFactory)context.getBean("entityManagerFactory");
EntityManager em=emf.createEntityManager();
My question is , is it an efficient way to ...

27. JPA not usable with CDI scopes that are managed in HttpSession?    stackoverflow.com

All CDI managed beans that belong to a scope that is ultimately bound to the HttpSession need to be serializable. Which means all attributes need to be serializable. EntityManager is not ...

28. how to @FilterJoinTable with EntityManager in Hibernate JPA?    stackoverflow.com

I would like to limit the data that is coming from OneToMany relation. In my program the boss account can view all the company's that have orders in the given month ...

29. How can the JPA recognize two classes with the same name but in different packages?    stackoverflow.com

I use JPA and Hibernate for my project. I have two classes with same names but in different packages. They are:

@Entity(name = "X_USER")
@Table(name = "X_USER")
public class User {
and:
@Entity
@Table(name="Y_USER")
public class User {
I ...

30. Hibernate Entity Manager    coderanch.com

31. Cannot undeploy hibernate-entitymanager.jar file    coderanch.com

I'm working on a webapp that uses JPA and Hibernate, deploying it on Tomcat. Things are moving along nicely, but I have one ongoing problem that is very frustrating. Whenever I undeploy my webapp, Tomcat leaves behind the "hibernate-entitymanager.jar" file in the "webapps\myapp\WEB-INF\lib" directory. That means I have to shutdown Tomcat entirely, manually delete the "webapps\myapp" directory and the "work\Catalina\localhost\myapp" directory, ...

32. JPA using Hibernate - Entity Manager doubts    coderanch.com

Hi dear friends, I'm learning about JPA and I've wrote a fairy simple application based on the Oreilly's EJB 3.0 Book. First, let me show you my classes and after that I'll tell what's happening. Cabin entity package com.titan.domain; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table(name="CABIN") public class Cabin implements Serializable { private int id; private ...

33. How to use datasource for Hibernate Entity Manager    coderanch.com

Hi, I need to read the database properties from a configurable properties file and set to the persistance.xml how can I do this for example if I need to change the database I need to go to persistance.xml and need to change the values, but I need like there should be a properties file in that I need to configure all ...

34. Hibernate Entity Manager    coderanch.com

35. Using Hibernate EntityManager    coderanch.com

JPA is where Hibernate is headed. In fact, the Hibernate people were some of the primary contributors to the JPA standard. For this reason, I would avoid the old Hibernate Session-based techniques and use the EntityManager - and JPA annotations. I use Spring and JPA to abstract my persistence layer from the higher levels of the app and it works quite ...

36. JPA - How to reconnect EntityManager    coderanch.com

I have source code public class Main { public static void main(String args[]) { EntityManager em = Persistence.createEntityManagerFactory("JPA_EjemploPU").createEntityManager(); try { System.out.println("Stop mysql"); Process p = Runtime.getRuntime().exec("net stop mysql"); Thread.sleep(5000); System.out.println("Start mysql"); p = Runtime.getRuntime().exec("net start mysql"); Thread.sleep(5000); } catch (Exception ex) { ex.printStackTrace(); } /* reconnect */ em = Persistence.createEntityManagerFactory("JPA_EjemploPU").createEntityManager(); Query q = em.createNamedQuery("AcClases.findAll"); List lista = q.getResultList(); for (AcClases acClases ...

37. Using Hibernate, is it important to use Hibernate Entity Manager?    coderanch.com

Hello Good day, I'm just wondering if i should use Hibernate Entity Manager in a project, My project is about multithreaded client-server application that requires to be thread-safe. My question is can Hibernate alone eliminate or prevent the concurrency issues? Does it have its own locking features(though i have read some things about pessimistic locking but not that well)? Thanks

38. Entity manager in Hibernate    coderanch.com

40. Configuration Problem? Entity Manager, OutOfMemory    forum.hibernate.org

jdbc:postgresql://localhost/bla postgres org.postgresql.Driver org.hibernate.dialect.PostgreSQLDialect bla org.hibernate.transaction.JDBCTransactionFactory ...

41. Documentation for EntityManager 3.5?    forum.hibernate.org

43. Custom UserType, entityManager and AssertionFailure    forum.hibernate.org

I have not used user-types myself, but have some experience with the Interceptor interface. In this interface it is clearly stated that it is not allowed to use the current session or trigger lazy initialization of proxies or collections. I guess the reason is to not mess up the internal state of the session or to cause infinite loops, etc. I ...

44. Entity Manager bug with ParameterExpressionImpl    forum.hibernate.org

Emmanuel There seems to be a bug with the ParameterExpressionImpl class when rendering. If you create a criteria query using a ParameterExpression instance in multiple places in your query the rendering of this query will produce multiple pram0, param1, param2 for the same ParameterExpression instance. We fixed this bug by augmenting the RenderingContext interface with generateParameterName(Expression exp). With this information the ...

45. What happened to Hibernate EntityManager?    forum.hibernate.org

I'm sure this is a stupid newbie question, but, what happened to Hibernate EntityManager? Do I have to use Maven now to get it??? What happened to the download? Note, I want the one that supports JPA 2. Why don't they just include the EntityManager jars with the 3.5.0 distribution download? This is HIGHLY FRUSTRATING. A user shouldn't have to dig ...

46. Entitymanager confusion    forum.hibernate.org

Hi! I am having some troubles understanding the current "way to go" for hibernate. I've always used hibernate session (sometimes with spring templates) so far. But now hibernate-entitymanager seems to be a lot more appealing (JPA 2.0). From my understanding the hibernate entitymanager somehow wraps arround the basic (session) core, is that correct? So it seems a little bit strange for ...

47. Hibernate Entity Manager    forum.hibernate.org

Hi All, I have facing some issue with Entity Manager. I have an web service which internally calls in EJB. There are some predefined methods into EJB. The method to which i am facing the issue is as follows: Quote: @stateless public class SampleEJB{ //inject the Entity manager EntityManager em; public method1(){ while(true){ Entity entity = em.createQuery("select Entity where col1 = ...

48. How to change entityManager.remove() behavior?    forum.hibernate.org

49. Nullpointer when creating Entitymanager with 3.6 and Oracle    forum.hibernate.org

Hi all, I have a weird problem.I have a Generic DAO library which uses Spring 3.0.4 and Hibernate 3.5.6 (core and Entitymanager). Everything works wonderful When I upgrade to the latest version of Spring 3.0.5. it still works. When I upgrade to Hibernate 3.6 Final (which is supposed to work with Spring 3.0.5) I get this weird error: java.lang.IllegalStateException: Failed to ...

51. One EntityManager or several EntityManager    forum.hibernate.org

Hi @all, I've got (a) very simple question(s). In most examples online several classes have got their own EntityManager. I think it's a waste to have to many EntityManager, isn't it? So I'd create one in a session bean (or realated) to it, so every session has exactly one EntityManager. All other classes will have access to this class. Does this ...

52. Access Hibernate diretctly from JPA EntityManager? (dirty!)    forum.hibernate.org

Hi folks, I am inside an EAR running withing Glassfish 2 with Hibernate as my persistence provider. So what I should do probably is use the JPA EntityManager. I would like to know if there is some way to work with the Hibernate session directly, although only the EntityManager is injected in my code? I am fully aware that this could ...

53. Problem in Using Hibernate EntityManager    forum.hibernate.org

I created 2 classes one Message.java with all annotation and it will be persisted.Other class HelloWorld.java which has main method and makes Use of Hibernate EntityManager. As told in gavin king's book i didnt created a hibernate.cfg.xml for this, instead i created this file structure in classpath META-INF/persistence.xml but as expected code didn't run and showed these exceptions:: Code: Exception in ...

54. Two questions regarding the hibernate-entitymanager module    forum.hibernate.org

Hi, 1- Some time ago it was announced that hibernate-core now also contains hibernate-entitymanager and this deprecates the compatibility matrix once we had to consult to manage our Hibernate dependencies. However some time ago Hibernate Core 3.6.5.Final was released, but apparently it does not exist in the Maven repo as the following Maven configuration is not able to resolve it for ...

55. Facing issue with EntityManager    forum.hibernate.org

Hi Friends, I have a Person entity and Address entity and there is @OneToMany relation b/w Person and address. See below mapping =================== @Entity @Table(name="Person") public class Person { @Id @GeneratedValue @Column(name = "p_id") private Long id; @OneToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH }) @JoinColumn(name = "p_id") private List

addressList = new ArrayList
(); setters and getters... ========================================== @Entity @Table(name="ADDRESS") public ...

56. entityManager to alter system tabels    forum.hibernate.org

I need to be able to lock/unlock accounts via 'ALTER USER username ACCOUNT LOCK' but how do I do that with an entitymanager? All I see is queries and while I can createNativeQuery and it runs without an error it does not actually alter the account. I have made sure that the user that the entitymanager s using has the permissions ...

57. Confuse about EntityManager    forum.hibernate.org

58. Entity Manager    forum.hibernate.org

Im trying to figure out this entity manager thing. So please bare with me. Why am I getting this error, the JDBC driver I use is in the classpath of my eclipse. Code: SEVERE: JDBC Driver class not found: java.lang.ClassNotFoundException: at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:109) at ...

59. Using Hibernate Entity Manager    forum.hibernate.org

60. Basic guide to move from Hibernate Core to EntityManager?    forum.hibernate.org

I'm working on a project (Java SE 5, Swing desktop app) that currently uses Hibernate for it's ORM solution. We're reworking some stuff (because we failed to keep good separation between the persistence layer and the UI layer). In the rework, we would like to move to a strictly 'portable' JPA-based solution. In other words, we would like to use as ...

61. EntityManager class autodetect issue    forum.hibernate.org

I am using Hibernate/Annotations/EntityManager 3.2.1 GA in JSE and I am having a problem with the EntityManager not loading classes from a directory other than the base where the persistence.xml resides. Here is my scenario: I am using Maven2 as my build environment and it creates the source class output in the ./classes directory and the test classes in the ./test-classes ...

62. Hibernate entity manager and Java Web Start    forum.hibernate.org

I am developing a java desktop application deployed via java web start. When the application is run, it gives me this error: Code: Caused by: java.lang.IllegalArgumentException: URI is not hierarchical at java.io.File.(Unknown Source) at org.jboss.util.file.ArchiveBrowser.getBrowser(Unknown Source) at org.hibernate.ejb.Ejb3Configuration.scanForClasses(Ejb3Configuration.java:610) ... 67 more I am using spring 2.0.2 and hibernate 3.2.1 ...

63. Implications of sharing an entity manager in a web app...    forum.hibernate.org

Hello, I would like to put an entity manager instance into the ServletContext/application scope of a web application. The reason for this is that I want to cache the results of a query (I want to use the query cache) and it seems that I need to put the entity manager either in session or in application scope in order for ...

64. Can we retrieve the HttpSession in the entity manager ?    forum.hibernate.org

The EntityManager has no clue about the HttpSession. If you need access to the HttpSession, your UI layer should perform that kind of work. If you need access to the HttpSession from the EM, your architecture could probably use some closer inspection/refactoring. Perhaps if you explained the need for this, I could guide you a bit in the right direction.

65. Positional Parameters with Hibernate Entity Manager    forum.hibernate.org

Hibernate version: hibernate-3.2.2.GA, hibernate-entitymanager-3.3.0.GA, hibernate-annotations-3.3.0.GA Hi all, I'm using hibernate with entity manager and annotations. I have the following code (please note the positional parameter used): Code: Query query = getEntityManager().createQuery("SELECT f FROM Application a JOIN a.fields f WHERE a.id = ?1"); query.setParameter(1, new Long(1)); if (_logger.isInfoEnabled()) { ...

66. SessionClosed, EntityManager    forum.hibernate.org

Similar threads: http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4066873#4066873 http://osdir.com/ml/user-groups.ajug.members/2007-01/msg00035.html Code: 16:57:15,093 ERROR [LazyInitializationException] failed to lazily initialize a collection of role: cz.test.specializationBeans, no session or session was closed org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: cz.test.specializationBeans, no session or session was closed at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358) at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350) ...

69. General Question About EntityManager LifeCycle    forum.hibernate.org

70. Hibernate EntityManager 3.3.2 beta 1 download    forum.hibernate.org

71. A bug in Hibernate Entity Manager    forum.hibernate.org

Hibernate entity manager seemed to have a problem with the following attribute in my class: Code: class Student { ... @OneToMany @JoinTable( joinColumns = {@JoinColumn(name = "student_id", referencedColumnName = "id")}, inverseJoinColumns = {@JoinColumn(name = "course_id", referencedColumnName = "id", unique = false)}) ...

72. Hibernate Entity Manager JPA issue on WebSphere 6.1    forum.hibernate.org

Hi, I am facing issue while using Hibernate based JPA implementation (Hibernate entity manager) on WebSphere 6.1 application server. Hibernate version in use is 3.3 The application in question gets deployed as EAR file. Following are some key information: JPA Usage: The application use case have JPA based DAO. The persistence.xml file has Hibernate as Provider. Case 1: - The JPA ...

73. How to use JPA with Hibernate Entity manager    forum.hibernate.org

Hi, I am facing a problem, I want to use JPA QL in order to use outer join with on clause (on report query). I am using JBOSS and EJB3 so I get entitymanager and I call createQuery method then query.getResultList(). But entitymanager seems to use HQL and not JPA QL because I have org.hibernate.hql.ast.QuerySyntax exception. How can I force to ...

74. Some odd Behavoir EntityManager    forum.hibernate.org

Hi everybody, i did some refactoring on my DAO's to optimize them. The find method works fine. I got some trouble when i used em.find(..) and after that em.remove(..). i always got an exception like "Removing a detached instance..". i solved this by changing find into getReference. However i'm not really satisfied with it cause i don't really understand why it ...

75. EntityManager and Hibernate Archive    forum.hibernate.org

I have two applications that I need to deploy, where both share the same hibernate entities. I have been looking into generating a HAR file and distributing with both my applications, inside each EAR. The HAR file is generated correctly and loaded by hibernate, as per JBoss' log files, however I can't quite figure out how to setup my persistence.xml file ...

76. Entitymanager in entitylistener    forum.hibernate.org

Hi All, I'm using ejb3 + jboss+ hibernate. When I persist an object I would like to persist another object automatically (maybe by using one of the following: interceptor, entitylistener or trigger). I tried to use the entitylistener but the problem is that I can't use the entitymanager in it. Do you have any solution to my request? Thanks alot! Dyahav ...

77. the right way to use createCriteria with EntityManager    forum.hibernate.org

Is this the right way to use createCriteria with entityManager ? Code: import javax.persistence.*; import org.hibernate.ejb.HibernateEntityManager; private javax.persistence.EntityManagerFactory emf; ClassName(){ emf= javax.persistence.Persistence.createEntityManagerFactory("PERSISTENCE_UNIT_TEST"); } public Collection getSomething(){ EntityManager em = emf.createEntityManager(); try { ...

78. oscache with JPA/HB entity manager not using disk    forum.hibernate.org

I'm using OSCache in two places in my application. In one place, it is being used in code "manually" to cache images. This configuration specified a non-existent directory for the disk cache, which gets created and populated at runtime, very much as I'd expect. In the other place, I'm using Hibernate EntityManager with OSCache as the second level cache. I'm providing ...

79. [JPA] How do i manage entity manager properly?    forum.hibernate.org

81. EntityManager manipulation of @Version    forum.hibernate.org

Why does a hibernate session ignore changes to an @Version column? Consider the situation where I load an object from DB and then update elements of it with the intention of persisting those changes--all within a single Hibernate session. If I change the "name" field of my bean and then merge, the change will commit to the DB. However, if I ...

82. Stored Procedure Issue with Hibernate Entity Manager    forum.hibernate.org

Newbie Joined: Tue Jul 28, 2009 11:52 am Posts: 4 Hello Everyone, I am trying to call stored procedure using Hibenate and JPA Entity Manager. I am utilizing annotations and the whole application is using Struts+Spring+ Hibernate combination. The database is Informix11.5. In the class mentioned below I created a NamedNativeQuery with query name="packageList". The stored procedure I am trying to ...

83. Hibernate Entity Manager.    forum.hibernate.org

Hi, We are using Hibernate Entity Manager with Seam Framework. Our Application has an Background process (Thread) which starts when the jboss server is started. When i try to instantiate EntityManager using @PersistenceContext inside the thread it gives entity Manager as null and the same i try inside an stateless session Bean it works fine. I am not sure why the ...

84. JPA and Entity manager.    forums.oracle.com

Hi all, I have a "simple" question: Should I create a class to manage entity manager and entity manager factory on JPA2? Why do I ask that? Because I read on J2EE tutorial: "... With a container-managed entity manager, an EntityManager instances persistence context is automatically propagated by the container to all application components that use the EntityManager instance within a ...