FAQ Database Discussion Community

Spring transaction and PersistenceContext

I've got situation like this: @Transactional @Override public void register(String username, UserPasswordNew userPasswordNew, UserAccount userAccount) throws UserNameAlreadyExistsException { ..... entityManager.merge(userAccountToSave); } I made some research but check me if I understand well. I've got entityManager (transaction scope). Method register is @Transactional so it means that this method is wrapped in...

Update/delete queries cannot be typed JPA

I'm using the Spring framework for working on training projects. I'm also using JPA and have been having a hell of a time. In my DAO implementation class, I've written: @Override public void deleteEntries(Module mod) { System.out.println(mod.getDescription()); entityManager.createQuery("delete from TrainingEntry e where e.module = :mod and e.completedDate IS NULL", TrainingEntry.class).setParameter("mod",...

EntityManager not injected in Stateless Session Bean

I have been looking through a lot of similar questions which did not reflect my exact problem. If i overlooked that someone already had this problem solved, please let me know. I am currently migrating an old EJB 2.1 application on JBoss 3.x to EJB 3.x on JBoss 7.x. Due...

Servlet does not persist an Entity

What do I want to do: I just started with JPA and therefore i want to understand how persisting Entitys from different perspectives work (Application-Managed, Container-Managed). Application-Managed works fine, however i have problems persisting an Entity with an Entity Manager from within a Web Application using a TestServlet. What have...

javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist?

I have Employee Class like below @Entity public class Employee{ @Id @GeneratedValue(strategy = GenerationType.AUTO) id; Department dept; Address add; @JoinColumn(name = "manager_emp_id", insertable = false, updatable = false) Manager Employee; //other fields and their getters and setters } when i call entityManager.persist(Employee emp) to persist i get below error javax.persistence.PersistenceException:...

Injecting EntityManager in servlet, it seems not thread safe

I want to make a login app in Java EE. I thought of implementing it using a html page, a servlet and an entity class for the user, but it seems that EntityManager is not thread safe (can't be injected in the servlet and I need it to check the...

Given a set of PK in a Java Set, how to select all rows with PK in the set

I have a set of primary keys in a Java Set (of member ID). How can I pull all the membership records from the membership table whose primary key is in the set? JPA code sample with EntityManager would really helpful as well. Thanks.

synchronize EntityManager with database

I deleted a record from the database, and the entity manager still references that deleted record. I have the following query: List results = em.createNamedQuery("Customers.findNew") .setParameter("status", "n") .getResultList(); I am getting back results which include the deleted record. I've read the entity manager caches the database for better performance. This...

CDI error: Ambiguous dependencies trying to inject EntityManager

I'm facing a strange error while trying to deploy my EJB 3.1 application in a JBoss 7.1.1 application server: WELD-001409 Ambiguous dependencies for type [EntityManager] with qualifiers [@Default] at injection point [[parameter 1] of [constructor] @Inject public br.com.sigga.siot.dao.masterdata.impl.ProfileDAOImpl(EntityManager)]. Possible dependencies [[Resource Producer Field [EntityManager] with qualifiers [@Any @Default] declared as...

Entity class must have non argumented constructor

I am studying JPA, so while studying on a JPA BLOG Vogella 1.2 Entity Heading, i came across a line which says: All entity classes must define a primary key, must have a non-arg constructor and or not allowed to be final I am not able to understand this line....

BreezeJs features already implemented by AngularJs?

I was suggested to use BreezeJs for an AngularJs project and I saw that it has some really interesting features. In my case the main interests would be in caching, tracking changes, some light querying, and validation. I think those features can be implemented at some level in AngularJs without...

Symfony2 insert multiple entities

I have a question about inserting multiple entities. What happens to the entities if i persist every entity in a loop and then i flush ? I mean what happens if one of this entities is duplicated and can't be inserted ? Are all entities removed or only the one...

When NOT to use EntityManager.flush()?

For synchronization and to retrieve the DB-generated ID's I feel coerced to call EntityManager.flush() at several places. Performance implications aside, are there reasons not to call flush()? In other words, is there any observable difference for the caller of my (DAO, ...) method if it does/doesn't flush()? My scenario is...

What's the difference beetwen EntityManager and DAO? [closed]

What's the difference beetwen EntityManager and DAO? Is it same thing?

EclipseLink JPA: list entities with reference variables

I am using JPA's eclipseLink to perform CRUD operations on my entities. I am facing following problem: I have two tables in DB: CREATE TABLE User ( id INTEGER PRIMARY KEY AUTO_INCREMENT, username VARCHAR(30) NOT NULL UNIQUE, email VARCHAR(50) NOT NULL UNIQUE, password VARCHAR(255) NOT NULL, signUpDate timestamp NOT NULL...

Using entityManager to get list from database

I've been working within the Spring MVC and have absolutely no clue what I'm doing. I'm trying to retrieve a list of objects (or records) from a database using entityManager. I have my method that doesn't seem to do anything: @Override public List<Module> sortStatus(String status) { String queryString = "SELECT...

Why is my EntityManager not properly injected?

I tried to build a project with manages Employees using JPA and Beans and JSF. I started trying to manipulated an existing user which I manually created in the database. (before I tried to read the data from the database, this worked well) I tried this in various ways, by...

Wildfly 8.0.0.Final + EntityManager + PostgreSQL - idle in transaction

I have the following code running on Wildfly 8.0.0.Final: @Stateful public class MyJPABean<T> { @PersistenceContext(unitName = "myUnitName") private EntityManager em; @TransactionAttribute(TransactionAttributeType.REQUIRED) public void write(T entity) { em.persist(entity); em.flush(); } @TransactionAttribute(TransactionAttributeType.REQUIRED) public void update(T entity) { em.merge(entity); } } Both write and update methods are called parallely, because they are called...

Spring transactions, EntityManager lifecycle

I am developing a project with spring framework. I have following architecture: all database code is in dao classes, all application logic is in service classes, http requests are processed using spring mvc rest controllers. @Repository public class UserDao { @PersistenceContext private EntityManager em; public void editUser(User user) { ......