entitymanager

EntityManagerFactory is closed, Hibernate

坚强是说给别人听的谎言 提交于 2020-06-25 18:10:05
问题 I have recently created a web service that uses a static method in Java to obtain a list of items from the database. The web service works perfectly and returns JSON back to the caller. However, it works only once. If you try to refresh or make a new request, I get a EntityManagerFactory is closed error. Here's how the Web Service class looks like: public class WebService extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws

EntityManagerFactory is closed, Hibernate

懵懂的女人 提交于 2020-06-25 18:09:54
问题 I have recently created a web service that uses a static method in Java to obtain a list of items from the database. The web service works perfectly and returns JSON back to the caller. However, it works only once. If you try to refresh or make a new request, I get a EntityManagerFactory is closed error. Here's how the Web Service class looks like: public class WebService extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws

EntityManagerFactory is closed, Hibernate

浪尽此生 提交于 2020-06-25 18:06:12
问题 I have recently created a web service that uses a static method in Java to obtain a list of items from the database. The web service works perfectly and returns JSON back to the caller. However, it works only once. If you try to refresh or make a new request, I get a EntityManagerFactory is closed error. Here's how the Web Service class looks like: public class WebService extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws

How to use Symfony autowiring with multiple entity managers

狂风中的少年 提交于 2020-03-22 09:13:09
问题 I would like to use the autowiring in a service that use 2 different entity manager. How to achieve something like that ? use Doctrine\ORM\EntityManager; class TestService { public function __construct(EntityManager $emA, EntityManager $emB) { } } My service.yml file use to be configured like that : app.testservice: class: App\Services\TestService arguments: - "@doctrine.orm.default_entity_manager" - "@doctrine.orm.secondary_entity_manager" 回答1: Dylan's answer violates the Demeter's Law

EntityManager is null when use in parallelStream

感情迁移 提交于 2020-03-06 09:43:13
问题 I have an EJB bean which have a method that call another method from the bean with parallel stream. It works fine, but in the async method I must update entity in the db and when I call entityManager.merge than I got a NullPointerExpcetion. I don't know why. I use OpenJPA on WebSphere. The original question was: Call a method for List in parallel? @Stateless public class TestBean implements LocalInterface, RemoterInterface { @PersistenceContext(unitName = Constants.PERSISTENCE_UNIT) protected

Find min and max on the same date field column and count using jpa entity manager criteriabuilder

南笙酒味 提交于 2020-03-04 16:31:12
问题 The bounty expires in 6 days . Answers to this question are eligible for a +50 reputation bounty. Prashant Kumar wants to draw more attention to this question. I am working on replacing below sql query and use entitymanager criteriabuilder. I checked other blogs and documentation but haven't been successful yet. SELECT MIN(creation_date),MAX(creation_date),COUNT(*), source FROM creation_tbl where creation_date>=? GROUP BY source; My current approach CriteriaBuilder criteriaBuilder =

JPA cascade all causing integrity constraint

五迷三道 提交于 2020-03-04 05:28:45
问题 I have three tables Employee, Boss, and Address. Employee and Boss in this case share the same Address. When I call EntityManager.remove on Employee I get an Integrity Constraint exception because it tries to delete the Address which it can't because Boss still needs it. If no one is using the Address though I would want it to be removed. What should my annotations look like so that I can delete orphans from Address but avoid the integrity constraint? Exception = Internal Exception: java.sql

How to use entitymanager with Micronaut?

落爺英雄遲暮 提交于 2020-02-06 07:38:42
问题 I'm new in Micronaut framework and I'm trying to use entitymanager to create my repository. I created my repository like this public interface EmployeeRepository { Employee save(@NotNull Employee employee); Employee update(@NotNull Employee employee); List<Employee> findAll(); Optional<Employee> findById(@NotNull Long id); } and I used this class to implement the interface and to inject entitymanager @Singleton public class EmployeeRepositoryImpl implements EmployeeRepository{

Entity update in EntityManager

我是研究僧i 提交于 2020-01-25 10:48:05
问题 Describe briefly the whole situation. I have an entity public class MovieEntity { ... @OneToMany(mappedBy = "movie", cascade = CascadeType.ALL) private Set<MovieOtherTitle> otherTitles; ... } I save a movie in the database using the JPA Spring Data repository this.movieRepository.save(movie); Then I add another title to the film final MovieOtherTitle movieOtherTitle = new MovieOtherTitle(otherTitle.getTitle(), otherTitle.getCountry()); movieOtherTitle.setMovie(movie); movieOtherTitle.setUser

Does an entity manager create a connection to the database?

不羁的心 提交于 2020-01-21 01:51:09
问题 In my project, I forgot to close the entity manager for each operation. After some time, I got exception due to excessive connections to mysql server. Does this mean that each entity manager establish the connection? What will happen when we forget to close the connection? I have used only one entity manager factory. 回答1: Assuming that you are using an application-managed entity manager, then you are responsible for initializing and closing the entity manager. One the other hand, if you are