entitymanager

Within JTA transaction (using container managed transaction), executeUpdate mehtod for explicit Query does immediate commit

做~自己de王妃 提交于 2019-12-11 11:16:48
问题 Within JBOSS 7.1 AS, I'm using container managed transaction. For each request, I do several entity updates. Most of the entities use "insert, merge, refresh" methods from EntityManager to manage the updates. However, there is one entity that uses explicit Query to do "executeUpdate" on the DB (see below for the code snippet). This sql update is immediately commited to the DB and it is not aligned with container managed transaction (like other entity updates). Is there anyway align explicit

Why JPA Entity select result changes on each even query?

拈花ヽ惹草 提交于 2019-12-11 09:29:53
问题 My question is related to strange read/select behavior when same query returns different results after each call. Description of my situation is written below: I have the following code, returning list of documents from DB @RequestMapping(value={"/docs"}, method = RequestMethod.GET) @ResponseBody public ArrayList<Document> getMetaData(ModelMap modelMap) { return (ArrayList<Document>)documentDAO.getDocuments(); } DocumentDAO.getDocuments looks like public List<Document> getDocuments() { Query

Hibernate Annotations self referencing class?

早过忘川 提交于 2019-12-11 07:51:19
问题 I have defined this Entity class, but it does not seem to save the children to the database. Any ideas? @Entity public class CategoryModel implements Model<CategoryModel>, Serializable { private static final long serialVersionUID = -4520507504770029807L; @Id @Field(index = Index.UN_TOKENIZED, store = Store.NO) private String id; @NotNull private String name; @ManyToOne private CategoryModel parent; @OneToMany(cascade = CascadeType.ALL, mappedBy = "parent") private List<CategoryModel> children

Null EntityManager using @PersistenceContext

戏子无情 提交于 2019-12-11 07:34:34
问题 I'm trying to use a simple coding with Spring Boot, using the @PersistenceContext in the entitymanager, to create a object in MySQL, but I'm getting that my entitymanager object is null and not sure why, because the method that is using the entitymanager hast the @transaction annotation. This is my code where I call the method to insert the data: import org.hibernate.service.spi.ServiceException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework

EntityManager and persist method not working properly

ε祈祈猫儿з 提交于 2019-12-11 04:59:36
问题 I'm in trouble here.. I'm new using Spring + Hibernate in a Java SE application... I'm trying to instantiate the entityManager, but it's not working I'm using the annotation @PersistenceUnit, like this: @PersistenceUnit public void setEmf(EntityManager emf) { this.emf = emf; } And it works "fine", but it doesn't persist =/ When I change to @PersistenceContext public void setEmf(EntityManager emf) { this.emf = emf; } It came out the following error: Exception in thread "main" org

hibernate jpa entitymanager commit not writing objects to the database

被刻印的时光 ゝ 提交于 2019-12-11 03:28:27
问题 I'm using hibernate JPA (without Spring) and it's working well, but I have come across a problem which has stumped me for the last 3 days. I have written some generic DAO classes and am using them to persist my objects. They all work fine, except for one class of object which is not being persisted. No exceptions are thrown. I've tried debugging inside the hibernate code and found that the reason the entity is not being persisted is that in the org.hibernate.event.def.DefaultFlushListener

How to force JBoss 4.2.3 to clear hibernate's session cache for every request?

拥有回忆 提交于 2019-12-11 03:13:30
问题 It seems to me that JBoss reuses entity managers and the underlying hibernate sessions for multiple requests. I have run a test which proves that in some cases the state of an entity may be out-dated even if it is just fetched using em.find() . How can I disable this behaviour and force to clear or throw away used sessions to ensure that each request is handled with clear cache? UPD: Here is an example case. HTTP request 1. A session bean creates an entity instance and stores it with field "A

annotated entity manager null pointed exception

我的梦境 提交于 2019-12-11 01:03:46
问题 I am doing a small project using JPA. I need to insert the employee object. For that when I use the annotated entity manager I got the NullPointer exception. But when I use the Normal EntityManager without using the annotation it is working fine. Do I need to configure somewhere else other than persistence.xml to work this examle fine? Please see the code below. public class EmployeeDao implements IEmployeeDao{ @PersistenceContext(unitName = "timesheet") private EntityManager entityManager ;

How could I do an interceptor for EntityManager.class

风格不统一 提交于 2019-12-10 23:56:45
问题 I want to audit insertions, updates, deletions, etc using entitymanager. For this, how could I do an interceptor for EntityManager.class that will work with EJB??? 回答1: You don't need to add an interceptor for that, simply use JPA's callback methods and/or entity listeners. With the first approach, you add to an entity methods declared with one of these annotations: @PrePersist , @PostPersist , @PreUpdate , @PostUpdate , @PreRemove , @PostRemove , or @PostLoad . The names are self-explanatory

Spring 4 recommended replacement of JpaTemplate

南笙酒味 提交于 2019-12-10 18:35:39
问题 I have a legacy project which was using Spring 3.0.x and made use of the JpaTemplate implementation provided by Spring. However, after upgrading to Spring 4.0.x I learned that JpaTemplate was deprecated as of Spring 3.2 I have seen suggestions to simply refactor out the use of JpaTemplate with EntityManager . However, replacing JpaTemplate with EntityManager is not sufficient as I discovered this project was wrapping the JpaTemplate calls in a JpaCallback , which in turn used entitymanager. I