entitymanager

Entity Manager not working in JavaFX

徘徊边缘 提交于 2019-12-01 12:34:45
问题 I'm using Persistence unit and Entity classes from Database, all in a JavaFx fxml Application, I succeeded importing all my tables as entities in my Model, the proble is that I get an exceptions and errors when I try to insert into an entity, here's my entire code public class SampleController implements Initializable { @PersistenceContext(unitName="RawdaPU") private EntityManager em; @FXML private Label label; @FXML private void handleButtonAction(ActionEvent event) { Moyendidactique

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

天大地大妈咪最大 提交于 2019-12-01 03:57:01
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 good practice anyway? I don't have much experience with JPA. However this'll be useful - In JPA you must either: - Create a new EntityManager for each transaction. - Call clear() after each transaction to clear the persistence context. Depends how many objects you

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

五迷三道 提交于 2019-12-01 00:41:20
问题 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 good practice anyway? 回答1: I don't have much experience with JPA. However this'll be useful - In JPA you must either: - Create a new EntityManager for each

JPA 2.1 Entity Graph returns duplicated results

怎甘沉沦 提交于 2019-11-30 20:32:52
I started using the new entity graph feature in JPA 2.1 to specify the Lazy collections that must be loaded. Consider following classes: @Entity @NamedQueries({ @NamedQuery(name="findWithFilterAttr","select a from A a where a.filterAttribute like :filter") }) @NamedEntityGraphs({ @NamedEntityGraph(name = "graph.childs", attributeNodes = @NamedAttributeNode("childs"))}) public class A{ @Id private long id; @OneToMany(mappedBy="parent") private List<B> childs; private String filterAttribute; } @Entity public class B{ @Id private long id; @ManyToOne private A parent; } When I execute the named

why EntityManager is null?

旧街凉风 提交于 2019-11-30 20:08:44
In my web applicaton I use OpenJPA on Apache Tomcat (TomEE)/7.0.37 server. I use Netbeans to auto generate class ("Entity Class from database..." and "Session Beans From Entity Class..."). At SessionBean (for example UserFacade) i want to get EntityManager: @Stateless public class UserFacade extends AbstractFacade<User> { @PersistenceContext(unitName = "CollDocPU") private EntityManager em; @Override protected EntityManager getEntityManager() { return em; } } but when i get it by above way I get null. When I make it by: @Override protected EntityManager getEntityManager() {

EntityManager doesn't refresh the data after querying

百般思念 提交于 2019-11-30 17:15:55
问题 My current project uses HSQLDB2.0 and JPA2.0 . The scenario is: I query DB to get list of contactDetails of person . I delete single contactInfo at UI but do not save that data ( Cancel the saving part). I again do the same query, now the result list is 1 lesser than previous result coz I have deleted one contactInfo at UI. But that contactInfo is still available at DB if I cross check. But if I include entityManager.clear() before start of the query, I get correct results every time. I dont

How to use JUnit tests with Spring Roo? (Problems with EntityManager)

北战南征 提交于 2019-11-30 14:34:16
I'm trying to write a JUnit test for a Spring Roo project. If my test requires use of the entity classes, I get the following Exception: java.lang.IllegalStateException: Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?) The Spring Aspects JAR looks to be configured correctly. In particular, I have the following in the pom.xml file: <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> <version>${spring.version}</version> </dependency> and <plugin> <configuration> <outxml>true</outxml>

Hibernate EntityManager, is it supposed to be used as a singleton?

筅森魡賤 提交于 2019-11-30 14:16:00
I am not using Spring so I am creating an instance of EntityManager within a class. I used Hibernate-Eclipse reverse engineering to auto-generate the classes. These classes all has an instance of EntityManager. I am not 100% sure how Hibernate works with the EntityManager so I am wondering if it is okay that so many instances of this class (EntityManager) are made, for example, will there be problems with transactions? Should I just make a separate class that distributes a static instance of an EntityManager for all my other classes? or does it not matter? EDIT: I see there's something called

Correct way to do an EntityManager query during Hibernate Validation

試著忘記壹切 提交于 2019-11-30 13:26:20
I'm a bit of a Java EE/EJB noob, but from the docs and other posts I've gathered you cannot query the database using the same entitymanager/session during entity validation. In general, the lifecycle method of a portable application should not invoke EntityManager or Query operations, access other entity instances, or modify relationships within the same persistence context.[43] A lifecycle callback method may modify the non-relationship state of the entity on which it is invoked. Translation please? This is pretty abstract...can it be explained in more concrete terms? It leads to more

@PersistenceContext EntityManager thread-safety in Spring and Java EE

陌路散爱 提交于 2019-11-30 12:32:16
EntityManager is not thread-safe by definition. Servlets specs says that in non-distributed environment and without implementing SingleThreadModel , there is only one servlet instance per definition . Therefore, in Java EE when you inject an EntityManager through the @PersistenceContext into Servlet's field - it's not thread safe: public class MyServlet extends HttpServlet { // Not thread-safe, should be using EMF instead. @PersistenceContext private EntityManager em; } Is this correct to say that even though the default scope of Spring beans is singleton, the EntityManager is thread-safe as