[jboss-cvs] jboss-seam/src/main/org/jboss/seam/framework ...
Gavin King
gavin.king at jboss.com
Sun Jun 17 21:20:26 EDT 2007
User: gavin
Date: 07/06/17 21:20:26
Modified: src/main/org/jboss/seam/framework EntityHome.java
HibernateEntityHome.java Home.java
Log:
fix a subtle but very dangerous bug where changes to an entity injected via the entityhome did not get flushed
Revision Changes Path
1.18 +20 -7 jboss-seam/src/main/org/jboss/seam/framework/EntityHome.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: EntityHome.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/framework/EntityHome.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- EntityHome.java 25 Feb 2007 15:36:37 -0000 1.17
+++ EntityHome.java 18 Jun 2007 01:20:26 -0000 1.18
@@ -35,7 +35,7 @@
@Transactional
public String update()
{
- getEntityManager().joinTransaction();
+ joinTransaction();
getEntityManager().flush();
updatedMessage();
return "updated";
@@ -44,7 +44,6 @@
@Transactional
public String persist()
{
- getEntityManager().joinTransaction();
getEntityManager().persist( getInstance() );
getEntityManager().flush();
assignId( PersistenceProvider.instance().getId( getInstance(), getEntityManager() ) );
@@ -55,7 +54,6 @@
@Transactional
public String remove()
{
- getEntityManager().joinTransaction();
getEntityManager().remove( getInstance() );
getEntityManager().flush();
deletedMessage();
@@ -66,11 +64,26 @@
@Override
public E find()
{
- getEntityManager().joinTransaction();
+ if ( getEntityManager().isOpen() )
+ {
E result = getEntityManager().find( getEntityClass(), getId() );
if (result==null) result = handleNotFound();
return result;
}
+ else
+ {
+ return null;
+ }
+ }
+
+ @Override
+ protected void joinTransaction()
+ {
+ if ( getEntityManager().isOpen() )
+ {
+ getEntityManager().joinTransaction();
+ }
+ }
public EntityManager getEntityManager()
{
1.14 +16 -3 jboss-seam/src/main/org/jboss/seam/framework/HibernateEntityHome.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: HibernateEntityHome.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/framework/HibernateEntityHome.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- HibernateEntityHome.java 29 Jan 2007 12:43:31 -0000 1.13
+++ HibernateEntityHome.java 18 Jun 2007 01:20:26 -0000 1.14
@@ -64,10 +64,23 @@
@Override
public E find()
{
+ if ( getSession().isOpen() )
+ {
E result = (E) getSession().get( getEntityClass(), (Serializable) getId() );
if (result==null) result = handleNotFound();
return result;
}
+ else
+ {
+ return null;
+ }
+ }
+
+ @Override
+ protected void joinTransaction()
+ {
+ getSession().isOpen();
+ }
public Session getSession()
{
1.22 +3 -0 jboss-seam/src/main/org/jboss/seam/framework/Home.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Home.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/framework/Home.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- Home.java 1 May 2007 16:43:51 -0000 1.21
+++ Home.java 18 Jun 2007 01:20:26 -0000 1.22
@@ -65,6 +65,7 @@
@Transactional
public E getInstance()
{
+ joinTransaction();
if (instance==null)
{
initInstance();
@@ -90,6 +91,8 @@
}
}
+ protected void joinTransaction() {}
+
protected E find()
{
return null;
More information about the jboss-cvs-commits
mailing list