[JBoss Seam] - Mixing @PersistenceContext with Seam Managed Persistence
by emsa
The following is happening to me when I'm using both @PersistenceContext and Seam Managed Persistence, maybe this is a no-no?
1. I have a Stateless Session Bean (not managed by seam) that is called by Quartz "once is while" to update some statistics in the database. This Bean is using '@PersistenceContext' to inject an EntityManager and it is successfull in updating the database.
2. I have a Bean that is managed by Seam that uses '@In(create = true) EntityManager em' to inject an EntityManager. This EntityManager fails to read the updated data from the database, if there's previoulsy read data this data is returned by the EntityManager no mather if the data in the database is updated.
Both Beans above lives in the same .ejb3 and .ear.
I have tried to turn of the Second Level Cache but that did not help.
I have found two ways to get the correct data:
1. use em.refresh( .. ) on the stale data return by the em in (2) above.
2. use @PersistenceContext in (2) above instead of '@In ...'
Is it really impossible to mix the two diffrent ways to get hold on the EntityManager?
Where is the data cached and why is the updated data not fetched by the Seam Managed EntityManager?
/Magnus
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3983724#3983724
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3983724
19Â years, 6Â months
[Persistence, JBoss/CMP, Hibernate, Database] - JBossRollbackException
by jactor
A strange situation!
I have persisted an entity bean, but when I try to read (READ) the entity back with a query object given by the entity manager, a rollback exception is thrown...
...my questions: why? and what can I do to avoid this?
The exception:
| org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=C6ZHZ0J/11, BranchQual=, localId=11] status=STATUS_NO_TRANSACTION; - nested throwable: (javax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value: nu.hjemme.user.persistence.MenuItem.name)
I have a entity called User which has the following relation:
| @IndexColumn(name = "menuItemsIndex")
| @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
| @JoinColumn(name = "userId")
| private List <MenuItem> menuItems = null;
|
The property of the MenuItem which is not supposed to be null:
| @Column(length = 15, nullable = false)
| private String name = null;
|
... again: why is this happening? It seems like it is trying to committ something when I only want to read from the database.
I try to read the database with an ejb query (EJBQL) but this exception is thrown before the query is compiled by hibernate.
I am using jboss-4.0.5.GA.
The exception is mentioning that it is not part of a transaction (status=STATUS_NO_TRANSACTION), but I would not think that this was necessary when reading. Another question regarding entity managers: It is stated that a entity manager has a transaction scope of the instantiating class. If you instantiate the entity manager in one class but use this instance with a sub class by invoking a method on the super class, will this affect the transaction scope?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3983721#3983721
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3983721
19Â years, 6Â months