entitymanager

EclipseLink, EntityManager with two persistence units needed

Hi, I have one jar library A (or project in eclipse), which has it's own persistence unit (META-INF/persistence.xml) and some entity classes, and another project (B) using this one. In project B there is also persistence unit and entity classes. In project B I need to use both entity classes from project A and B. But if I set "A" as pe...

How to implement update () method in DAO using EntityManager (JPA)?

What is the standard way to implement simple update? Example: we have User with phone number NNNNNN and now we want to set it to YYYYYY. @PersistenceContext private EntityManager em; public void update (User transientUser) { what should be here? } User entity is as simple as possible: @Entity @Table (name = "USER") public clas...

In Spring, how do I use a ClassPathXmlApplicationContext to get an EntityManager?

With Spring I can autowire a bean with the following property: @PersistenceContext(unitName="foo") private EntityManager em; Using the following I can manually autowire the bean "someBean": ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("META-INF/applicationContext.xml"); AutowireCapableBeanFactory fac...

Persisting a new but identical entity with JPA reporting duplicate entry

I have a JPA project connected to a MySQL database where my entity object is mapped to a table with a constraint on 2 columns. That is: @Entity @Table(name = "my_entity") class MyEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @Column(name = "id") private Integer id; @Bas...

EntityManager fails to instantiate using JPA/Hibernate when I add a OneToMany annotation

I have been struggling with not being able to have the EntityManager be instantiated when I add a OneToMany column to a class that already has a OneToMany column. Right now the EducationInfo has a OneToOne to user, since each row will be unique to a person, but I want to be able to load all the education information given a username. I...

EntityManager initialization best practices

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 client will communicate with a stateful session bean, and each bean needs to use EntityManager at some point. I guess that bean methods are invoc...

EntityManager.merge inserts duplicate entities

Hi all, I've got a pretty special setup: I create all the classes in Java, connect them in my application (several ManyToOne-relationships). Then, I'd like to iterate over my objects and save them into the database. Sometimes, an object is already in the database, then it should not be persisted again. I implemented the hashCode() and...

Spring + Hibernate + JPA

As of now I have a working Spring application with persistence. However now I want to use Hibernate with JPA to do all of my database activities. I want to do this using an entitymanager. I've been reading many documents and tutorials on this matter, I've been getting confused on whether I need a persistence.xml file or not. Also I've ...

EntityManager refresh problem

I'm getting this error from my EntityManager when I call the refresh function. public void saveProduct(Product product) { entityManager.refresh(product); } I heard this could be a bug with Spring/Hibernate, however I'm not sure how to get around this. Edit: the error is java.lang.IllegalArgumentException: Entity not managed or...

Am I supposed to call EntityManager.clear() often to avoid memory leaks?

I'm new to JPA/OpenJPA and I noticed that if I don't call EntityManager.clear() after i persist entities I get an OutOfMemoryError (I keep adding new entities in a loop). I'm not sure if this is the expected behavior or it's just and OpenJPA 1.2.1 glitch. So, am I required to explicitly detach the entities myself? If I'm not, it's a go...

How to safely read related Entities from a detached Entity in JPA

I am trying to attach a related persisted entity to a transient entity. This works fine in GlassFish V2 but not in GlassFish V3. This is a very simple scenario. Please look at the testcase at QueryException when reading Property of detached Entity Many thanks. ...

Glassfish JPA: Problems injecting EntityManager

Hi I am new to Java EE. I tried to get some first examples running (JPA). I am using Glassfish v3. The trouble is that I don't get the App Server injecting the EntityManager. Hear is one example http://www.adam-bien.com/roller/abien/entry/ejb_3_persistence_jpa_for which I extended with a JSP client. Entity: package beans; import ...

Problem on jboss lookup entitymanager

I have my ear-project deployed in jboss 5.1GA. From webapp i don't have problem, the lookup of my ejb3 work fine! es: ShoppingCart sc= (ShoppingCart) (new InitialContext()).lookup("idelivery-ear-1.0/ShoppingCartBean/remote"); also the iniection of my EntityManager work fine! @PersistenceContext private EntityManager manager; Fr...

Spring, Hibernate, EntityManager and class inheritance

Hi, I'm pretty much new to Spring & Hibernate. In our team, we are building a web application using Struts 2 for the presentation layer, with Spring 3 and Hibernate 3 (with Annotations) underneath. We are still debating on whether to use DAOs or not and Session's or EntityManager's for CRUD operations. Setting aside the question of which...

How do I get spring to inject my EntityManager?

I'm following the guide here, but when the DAO executes, the EntityManager is null. I've tried a number of fixes I found in the comments on the guide, on various forums, and here (including this), to no avail. No matter what I seem to do the EntityManager remains null. Here are the relevant files, with packages etc changed to protect ...

GoogleAppEngine : ClassNotFoundException : javax.jdo.metadata.ComponentMetadata

I'm trying to deploy my application to a locally running GoogleAppEngine development server, but I'm getting the following stack trace when I start the server Apr 23, 2010 9:03:33 PM com.google.apphosting.utils.jetty.JettyLogger warn WARNING: Nested in org.springframework.beans.factory.BeanCreationException: Error creating bean with na...

Websphere 7 EntityManagerFactory creation problem

Hello, 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 EntityMan...

jdbctemplate query() vs entityManager createQuery()

Hi. What is essential difference between these methods? query() of JdbcTemplate and createQuery() of EntityManager? As I understand, both execute query? ...

flex/actionscript client entity state refresh on JPA update using Pimento EntityManager

My Flex application uses a client-side pimento EntityManager which fetches quite a few objects and associations. It does this by forcing eager fetching of particular association ends in the form of fetch plans. I would like to update the client whenever a change has been made to an entity existing in the EntityManager's cache. Is it poss...

How to persist every new entity?

I expect every instantiated entity to correspond to a tuple (& co) in the database. In the examples I see around, one always instantiates the entity (via a constructor) and then calls persist with that entity. I find this error-prone, and was wondering if it wasn't possible to have every instantiated entity automatically managed/persiste...