entitymanager

EnityManager Injection via HK2 in WebSockets

风格不统一 提交于 2019-12-13 03:12:53
问题 I have written 2 WebSocket ServerEndpoints that inject Services that themselves interact with the Database using injected instances of the JPA EntityManager. The application is a web application deployed on a Tomcat Server, using Jersey as JAX-RS implementation and Hibernate as JPA Provider. Sometimes it happens that the EntityManager is closed when trying to the DB inside the Endpoints. Also I fear I might have produced code that triggers a Memory Leak. This is the custom ServerEndpoint

What is happening inside applicationContext.xml

拥有回忆 提交于 2019-12-13 02:46:54
问题 Will someone please explain what the following applicationContext.xml file is doing? For greater context, I get it from http://persistentdesigns.com/wp/jersey-spring-and-jpa/. Some of my questions (not exhaustive, since I really don't understand much): For id="dataSource" is dataSource a keyword or is it the name of the datasource I am to use? For example, if the name of my datasource is actuall learningRestDS, do I replace dataSource with learningRestDS ? Why is the datasource class name org

Hibernate does not refresh entity childs completely

好久不见. 提交于 2019-12-12 18:10:04
问题 I use Hibernate 5.1.0.Final. My GenericDAO class main methods: public T save(T entity) { entityManager.getTransaction().begin(); entityManager.persist(entity); entityManager.getTransaction().commit(); } public T find(Long entityId) { T e = (T) entityManager.find(type, entityId); entityManager.refresh(e); return e; } I have Item entity which contains List<Image> images . @Entity @Table(name="item") public class Item extends GenericEntity { @Column(name="title") String title; @OneToMany(fetch =

Symfony 3 - EntityManager dependency injection with multiple db connections

落爺英雄遲暮 提交于 2019-12-12 16:12:32
问题 I have setup a Custom Authenticator using guard and auto wired the service. This is tested and works fine with just MySQL configured. I have now specified a second database connection (oracle), but Symfony will now not allow autowiring in my service configuration, because it does not know which database connection to use when injecting EntityManager in to the custom Authenticator class. Any idea how I can Configure the Dependency Injection to use a specific database connection so I can

How to get jpa datasource properties from Entity Manager

二次信任 提交于 2019-12-12 10:42:59
问题 Hi everybody I was wondering if it's possible to get database connection properties through entity manager. My persistence.xml looks like this <persistence ...> <persistence-unit name="default" transaction-type="JTA"> <jta-data-source>DatasourceForTestSystem</jta-data-source> <class> some.package.and.some.Class </class> ... </persistence-unit> </persistence> I want something like String host = em.getSomeFunction().getProperties().get("server"); String database = em.getSomeFunction()

JPA EntityManager and JavaFx [duplicate]

一世执手 提交于 2019-12-12 10:24:23
问题 This question already has an answer here : Can't create a EntityManager in JavaFx (1 answer) Closed 6 years ago . I tried to use EntityManager in a JavaFx application in NetBeans (my solution is connected to postgres), I proceeded as follows : 1) I created a Persistence Unit. 2) Then Added the Entity Classes from Database. but I can't get it to work, I tried to ask for some help in another thread Entity Manager not working in JavaFX but can't get it work either, is there any clean and clear

Inject additional configuration into custom Entity/Document Manager

◇◆丶佛笑我妖孽 提交于 2019-12-12 02:35:45
问题 I made a custom Document Manager for my project implementing some new low level functions (following this post). Now I would like to inject a custom configuration in my new Document Manager (I suppose it would be the same with an Entity Manager). I have no idea of how to do this... I want this config in my yaml files to set my custom Document Manager's parameters. The only way I found until now is to write a static function returning a hardcoded array of configuration, but it's a little dirty

Delete rows in a batch using JPA EntityManager

流过昼夜 提交于 2019-12-11 19:19:46
问题 I was trying to delete rows in a batch using JPA EntityManager. I got the following exception. java.lang.IllegalStateException: Not allowed to create transaction on shared EntityManager - use Spring transactions or EJB CMT instead at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:199) at $Proxy783.getTransaction(Unknown Source) at admin.dao.CountryDAO.delete(CountryDAO.java:109) at sun.reflect

Hibernate Update table with foreign key

ぐ巨炮叔叔 提交于 2019-12-11 17:29:25
问题 Am new to hibernate. Am trying to update a table and ended up getting java.sql.SQLIntegrityConstraintViolationException: Duplicate entry for key 'PRIMARY' exception Am using entityManager.merge() method to update the table. Below are the table relationships TableA( @ID int col A , String colB....) TableB( @ID int col X , @ManyToOne @Id @JoinColumn(name = "colA",referencedColumnName = "colA") TableA tableA ....) I have used Entitymanager.persist() to insert data in both the tables. Now i want

EntityManager create native query vs persist and injections

只愿长相守 提交于 2019-12-11 12:34:06
问题 Is createNativeQuery() safe against SQL injection if used as in: @ManagedBean @ViewScoped public class UserController { @PersistenceContext private EntityManager em; public User register(User u) { Query query = em.createNativeQuery("SELECT r1_register(?,?,?,?,?,?,?)"); short i = 0; query.setParameter(++i, u.getUsername()); query.setParameter(++i, u.getPassword()); query.setParameter(++i, u.getName()); query.setParameter(++i, u.getSurname()); query.setParameter(++i, u.getEmail()); query