FAQ Database Discussion Community


Symfony2 insert multiple entities

symfony2,entity,entitymanager,persist
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...

Spring transactions, EntityManager lifecycle

java,spring,transactions,entitymanager
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) { ......

synchronize EntityManager with database

java,jpa,entitymanager
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...

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

java,hibernate,postgresql,wildfly,entitymanager
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...

Update/delete queries cannot be typed JPA

java,spring,jpa,entitymanager,sql-delete
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

java-ee,ejb,jboss7.x,entitymanager
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...

Injecting EntityManager in servlet, it seems not thread safe

java-ee,servlets,jpa,dependency-injection,entitymanager
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...

Entity class must have non argumented constructor

java,hibernate,jpa,eclipselink,entitymanager
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....

Servlet does not persist an Entity

java-ee,servlets,jpa,persistence,entitymanager
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...

Using entityManager to get list from database

java,spring-mvc,entitymanager
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?

jpa,ejb,wildfly,entitymanager
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...

BreezeJs features already implemented by AngularJs?

javascript,angularjs,breeze,entitymanager
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...

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

java,java-ee,dao,entitymanager
What's the difference beetwen EntityManager and DAO? Is it same thing?

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

java,hibernate,jpa,entitymanager
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:...

CDI error: Ambiguous dependencies trying to inject EntityManager

jboss7.x,cdi,entitymanager,jboss-weld
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...

EclipseLink JPA: list entities with reference variables

java,jpa,eclipselink,entitymanager
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...

Spring transaction and PersistenceContext

proxy,transactions,entitymanager
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...

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

mysql,jpa,select,set,entitymanager
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.

When NOT to use EntityManager.flush()?

java,jpa,eclipselink,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...