Re: Tapestry Transactions

2012-05-31 Thread Steve Eynon
This now is all in the realm of Spring so I don't want to say too much...

Essentially, it doesn't matter how many 'nested' method calls you
make, [with PROPAGATION_REQUIRED] the transaction will rollback to
(and commit at) where the annotation was first encountered.

See the Spring docs for more:
http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/transaction.html#tx-propagation

@Transactional just gives you finer grained control over rollback
points and read access.

Steve.

On 31 May 2012 05:25, bhorvat horvat.z.bo...@gmail.com wrote:
 Can you elaborate a bit more the part below


 Steve Eynon wrote

 unlike T5's @CommitAfter, it doesn't always commit or start a new
 transaction.


 The T5 annotation always commits when there is not RuntimeException so what
 does @Transactional annotation does then :S

 tnx



 --
 View this message in context: 
 http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713540.html
 Sent from the Tapestry - User mailing list archive at Nabble.com.

 -
 To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
 For additional commands, e-mail: users-h...@tapestry.apache.org


-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Transactions

2012-05-31 Thread Jonathan Barker
Spring transaction handling makes some things so much easier.  For
example, on an admin page, I may want to simply save changes to an
object by making a call to a makePersistent() method on a DAO.  Of
course I want that to be committed.  That's why I said
makePersistent()  On the other hand, I might have some batch import
service that calls other transactional services, that invoke
makePersistent on DAO's hundreds or thousands of times, and I need
everything to happen within a transaction (the batch is in, or it
isn't, but I'm never left with cleanup to do).

Spring can automatically start a new transaction, or join an existing
one, as required.  It's a much richer transaction management tool.
It's a major reason I still use Spring.

Regards,
Jonathan

On Wed, May 30, 2012 at 5:25 PM, bhorvat horvat.z.bo...@gmail.com wrote:
 Can you elaborate a bit more the part below


 Steve Eynon wrote

 unlike T5's @CommitAfter, it doesn't always commit or start a new
 transaction.


 The T5 annotation always commits when there is not RuntimeException so what
 does @Transactional annotation does then :S

 tnx



 --
 View this message in context: 
 http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713540.html
 Sent from the Tapestry - User mailing list archive at Nabble.com.

 -
 To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
 For additional commands, e-mail: users-h...@tapestry.apache.org




-- 
Jonathan Barker
ITStrategic

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Transactions

2012-05-30 Thread Steve Eynon
Yeah, you can put the Spring @Transactional annotation on any Spring
bean / service. Both on the class and its methods.

The propagation=Propagation.REQUIRED ensures the code runs inside a
transaction but unlike T5's @CommitAfter, it doesn't always commit or
start a new transaction. It sounds like this does what you want.

Steve.

On 25 May 2012 21:33, bhorvat horvat.z.bo...@gmail.com wrote:
 So you put your transactional annotation on the DAO, right? The CommitAfter
 does that for me as well, what I need is to put it on some layer above that
 has multiple contats to the couple of different DAOs. One that saves one
 part of the transaction, other that saves another but the should fail or
 success together, can I do this with you configuration? Can I put
 Transactional annotation on something other then HibernateDAO.


 --
 View this message in context: 
 http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713416.html
 Sent from the Tapestry - User mailing list archive at Nabble.com.

 -
 To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
 For additional commands, e-mail: users-h...@tapestry.apache.org


-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Transactions

2012-05-30 Thread bhorvat
Can you elaborate a bit more the part below


Steve Eynon wrote
 
 unlike T5's @CommitAfter, it doesn't always commit or start a new
 transaction. 
 

The T5 annotation always commits when there is not RuntimeException so what
does @Transactional annotation does then :S

tnx



--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713540.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Transactions

2012-05-25 Thread bhorvat
Hi Steve,

Thanks for posting. Can I ask you to help a bit more :)

I have tried adding to pom tapestry-spring but it didn't resolve everything.
I was under the impression that tapestry-spring includes everything spring
related that is needed. The missing dependencies are related to hibernate

import org.springframework.orm.hibernate3.SessionFactoryUtils;
import org.springframework.orm.hibernate3.SessionHolder;
import
org.springframework.transaction.support.TransactionSynchronizationManager;


Also will I need to do anything from this page 

http://tapestry.apache.org/integrating-with-spring-framework.html

Something like 


  filter
filter-nameapp/filter-name

   
filter-classorg.apache.tapestry5.spring.TapestrySpringFilter/filter-class
  /filter

So if you can share a bit more light on the configuration (how did you
define services, since mine are defined in the code as normal tapestry
service, as your custom OpenSessionInViewFilter), how do I plug in the
filter into the tapestry (do I have to), do I have to change the hibernate
configuration that I have so far, since my project does not use spring.

Cheers and thanks for posting and helping

--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713407.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Transactions

2012-05-25 Thread Steve Eynon
Our dependencies are configured via Ivy:

dependency org=org.hibernate name=hibernate-core
rev=3.6.1.Final conf=compile
artifact name=hibernate-core ext=jar/
/dependency

dependency org=org.springframework name=spring-core
rev=3.1.0.RELEASE conf=compile/
dependency org=org.springframework name=spring-context
rev=3.1.0.RELEASE conf=compile/
dependency org=org.springframework name=spring-tx
rev=3.1.0.RELEASE conf=compile/
dependency org=org.springframework name=spring-jdbc
rev=3.1.0.RELEASE conf=compile/
dependency org=org.springframework name=spring-context-support
rev=3.1.0.RELEASE conf=compile
artifact name=spring-context-support ext=jar/
/dependency

And yes, you need to use the Spring filter in your web.xml because
your transactional services will be Spring services - configured in
the usual Spring way via the application-context.xml.

Example DAO:

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Transactional(propagation=Propagation.REQUIRED,
isolation=Isolation.READ_COMMITTED, readOnly = true)
public class MyHibernateDAO extends HibernateDaoSupport {

  ...

}

Hope it helps,

Steve.
--
Steve Eynon
---
If at first you don't succeed,
   so much for skydiving!



On 25 May 2012 17:26, bhorvat horvat.z.bo...@gmail.com wrote:
 Hi Steve,

 Thanks for posting. Can I ask you to help a bit more :)

 I have tried adding to pom tapestry-spring but it didn't resolve everything.
 I was under the impression that tapestry-spring includes everything spring
 related that is needed. The missing dependencies are related to hibernate

 import org.springframework.orm.hibernate3.SessionFactoryUtils;
 import org.springframework.orm.hibernate3.SessionHolder;
 import
 org.springframework.transaction.support.TransactionSynchronizationManager;


 Also will I need to do anything from this page

 http://tapestry.apache.org/integrating-with-spring-framework.html

 Something like


  filter
    filter-nameapp/filter-name


 filter-classorg.apache.tapestry5.spring.TapestrySpringFilter/filter-class
  /filter

 So if you can share a bit more light on the configuration (how did you
 define services, since mine are defined in the code as normal tapestry
 service, as your custom OpenSessionInViewFilter), how do I plug in the
 filter into the tapestry (do I have to), do I have to change the hibernate
 configuration that I have so far, since my project does not use spring.

 Cheers and thanks for posting and helping

 --
 View this message in context: 
 http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713407.html
 Sent from the Tapestry - User mailing list archive at Nabble.com.

 -
 To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
 For additional commands, e-mail: users-h...@tapestry.apache.org


-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Transactions

2012-05-25 Thread bhorvat
So you put your transactional annotation on the DAO, right? The CommitAfter
does that for me as well, what I need is to put it on some layer above that
has multiple contats to the couple of different DAOs. One that saves one
part of the transaction, other that saves another but the should fail or
success together, can I do this with you configuration? Can I put
Transactional annotation on something other then HibernateDAO. 


--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713416.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Transactions

2012-05-23 Thread Steve Eynon
;

private PageRenderEventHandler(ComponentRequestHandler handler,
PageRenderRequestParameters parameters) {
this.handler = handler;
this.parameters = parameters;
}

@Override
public void doStuff() throws IOException {
handler.handlePageRender(parameters);
}
}

private final class ComponentEventHandler implements EventHandler {
private final ComponentRequestHandler handler;
private final ComponentEventRequestParameters parameters;

private ComponentEventHandler(ComponentRequestHandler handler,
ComponentEventRequestParameters parameters) {
this.handler = handler;
this.parameters = parameters;
}

@Override
public void doStuff() throws IOException {
handler.handleComponentEvent(parameters);
}
}

private interface EventHandler {
void doStuff() throws IOException;
}
}



On 23 May 2012 05:53, bhorvat horvat.z.bo...@gmail.com wrote:
 You are right I wont pollute this mail thread with that anymore, I will try
 to do a bit more research on one vs the other.

 But in the mean time if anyone has any suggestion and nice links about
 spring-transactions and OSIVF please share it will be of great help

 cheers

 --
 View this message in context: 
 http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713343.html
 Sent from the Tapestry - User mailing list archive at Nabble.com.

 -
 To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
 For additional commands, e-mail: users-h...@tapestry.apache.org


-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Tapestry Transactions

2012-05-22 Thread bhorvat
What is the best way to handle complex transaction in Tapestry?

Up to this point I had a bunch of services that have @CommitAfter annotation
on them, and then I have a method say addNewSomething() in which I call a
create a bunch of objects all conected to each other and then call
appropriate services to persist them. The obvious problem is that each
persist is not depended on the next one as it should be. 

So now I am trying to put @CommitAfter anotation on the method
addNewSomething and this works in some cases (for adding for example, but
not for deleting - when I have to delete some object/objects from DB). Not
really sure why is that

Anyway what whould be the best way to handle this? Should I maybe consider
spring and @Transactional annotation. 

Also is OpenSessionInViewFilter something that should be used in tapestry?
It is my understanding that this is used because we first load an object and
then when in the tml we have a call to list of objects that are not loaded
it will throw an exception. However this does not happen for me. What it
does happen is that if I load an object but in some method that is called on
say form submit I need a list it will then throw an exception, but
OpenSessionInViewFilter does not help with that, right? So I am right to
assume that tapestry-hibernate has its own version of
OpenSessionInViewFilter?

Cheers

--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Transactions

2012-05-22 Thread Thiago H. de Paula Figueiredo
On Tue, 22 May 2012 07:42:08 -0300, bhorvat horvat.z.bo...@gmail.com  
wrote:



What is the best way to handle complex transaction in Tapestry?


As Tapestry nor Tapestry-IoC don't have support for more complex  
transaction scenarios, maybe you should consider using Spring or EJB for  
them.


--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor

Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Transactions

2012-05-22 Thread Dragan Sahpaski
Here's a nice blog post form tawus fro extended transactional support
http://tawus.wordpress.com/2011/04/23/tapestry-magic-5-advising-services/

Cheers,
Dragan Sahpaski



On Tue, May 22, 2012 at 1:47 PM, Thiago H. de Paula Figueiredo 
thiag...@gmail.com wrote:

 On Tue, 22 May 2012 07:42:08 -0300, bhorvat horvat.z.bo...@gmail.com
 wrote:

  What is the best way to handle complex transaction in Tapestry?


 As Tapestry nor Tapestry-IoC don't have support for more complex
 transaction scenarios, maybe you should consider using Spring or EJB for
 them.

 --
 Thiago H. de Paula Figueiredo
 Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
 and instructor
 Owner, Ars Machina Tecnologia da Informação Ltda.
 http://www.arsmachina.com.br


 --**--**-
 To unsubscribe, e-mail: 
 users-unsubscribe@tapestry.**apache.orgusers-unsubscr...@tapestry.apache.org
 For additional commands, e-mail: users-h...@tapestry.apache.org




Re: Tapestry Transactions

2012-05-22 Thread bhorvat
Any thoughts on OpenSessionInViewFilter? 

Is there any tapestry spring transaction example that you know of?

cheers

--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713309.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Transactions

2012-05-22 Thread bhorvat
The blog looks nice but this is not something that I would like to include my
self. btw did you try out his example or did you just stumble upon?

cheers

--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713310.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Transactions

2012-05-22 Thread Dragan Sahpaski
On Tue, May 22, 2012 at 3:34 PM, bhorvat horvat.z.bo...@gmail.com wrote:

 Any thoughts on OpenSessionInViewFilter?


Yes. It's an anipattern (search it on google).  Don't use it. I avoid
detached entities, or keeping them in some serialized form.
tapestry's ValueEncoder principle follows the principle of converting
client side to server side state and thats all you need.

Give me an example where you need the OpenSessioninViewFilter and we'll
work it out where you can do it without it.


 Is there any tapestry spring transaction example that you know of?

Nope.


 cheers

cheers


 --
 View this message in context:
 http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713309.html
 Sent from the Tapestry - User mailing list archive at Nabble.com.

 -
 To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
 For additional commands, e-mail: users-h...@tapestry.apache.org




Re: Tapestry Transactions

2012-05-22 Thread bhorvat
The thing is I am not sure for what it is used in the first place. Based on
everything that I have read it it seams to me that you use it to keep the
session open until you are done with the rendering of the tml. Say that you
load an object and that object has a list of objects in it, and you try to
access the list in the tml page with say the loop component. Now if you dont
use the OpenSessionInViewFilter you should get an exception
(LazyInitalization). However I dont get that exception, so I was wondering
(since most of the stuff for OSIVF is a bit old) is tapestry now handling
this itself (tapestry-hibernate that is) or am I miss understanding what the
filter is used for in the first place?

I would like to solve 2 problems with this transaction. The first one is the
LazyInitalization. I always have to reload the object in the methods that
handle the form if I need to use some list of objects that have not been
used when the page was rendered. 

The second problem is that I want to put Transaction annotation or something
like that so that I have transaction behavior instead of having every part
of (what should be single transaction) commit independently.

tnx for your help

cheers

--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713314.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Transactions

2012-05-22 Thread Dragan Sahpaski
On Tue, May 22, 2012 at 3:59 PM, bhorvat horvat.z.bo...@gmail.com wrote:

 The thing is I am not sure for what it is used in the first place. Based on
 everything that I have read it it seams to me that you use it to keep the
 session open until you are done with the rendering of the tml.

Yes. The hibernate session (just a remainder).


 Say that you
 load an object and that object has a list of objects in it, and you try to
 access the list in the tml page with say the loop component. Now if you
 dont
 use the OpenSessionInViewFilter you should get an exception
 (LazyInitalization).

Yes but only if the session is close.


 However I dont get that exception, so I was wondering
 (since most of the stuff for OSIVF is a bit old) is tapestry now handling
 this itself (tapestry-hibernate that is) or am I miss understanding what
 the
 filter is used for in the first place?

No.


 I would like to solve 2 problems with this transaction. The first one is
 the
 LazyInitalization. I always have to reload the object in the methods that
 handle the form if I need to use some list of objects that have not been
 used when the page was rendered.


Yes . Why is that unusable for you? The LazyInitalization is caused because
the entity is from another session (detached) and you are trying to access
a lazy property.




 The second problem is that I want to put Transaction annotation or
 something
 like that so that I have transaction behavior instead of having every part
 of (what should be single transaction) commit independently.


CommitAfter is a nice example. But CommitAfter doesn't support nested
transactions. For this you'll need your own advice - or just don't call
@CommitAfter annotated methods in a transaction (other @CommitAfter
methods).


 tnx for your help

 cheers

 --
 View this message in context:
 http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713314.html
 Sent from the Tapestry - User mailing list archive at Nabble.com.

 -
 To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
 For additional commands, e-mail: users-h...@tapestry.apache.org




Re: Tapestry Transactions

2012-05-22 Thread Denis Stepanov
OpenSessionInViewFilter has nothing to do with detached entities, it only keeps 
session open till view is rendered otherwise lazy loading will no work. The 
filter is trying to solve it by always opening session in every request and 
closing it at the end. Tapestry hibernate opens session only when it is needed 
and closes it when thread is finished, it is how it should be, but if you use 
spring hibernate + tx you need to use it there is no way around it.

Denis

May 22, 2012 v 3:59 PM, bhorvat:

 The thing is I am not sure for what it is used in the first place. Based on
 everything that I have read it it seams to me that you use it to keep the
 session open until you are done with the rendering of the tml. Say that you
 load an object and that object has a list of objects in it, and you try to
 access the list in the tml page with say the loop component. Now if you dont
 use the OpenSessionInViewFilter you should get an exception
 (LazyInitalization). However I dont get that exception, so I was wondering
 (since most of the stuff for OSIVF is a bit old) is tapestry now handling
 this itself (tapestry-hibernate that is) or am I miss understanding what the
 filter is used for in the first place?
 
 I would like to solve 2 problems with this transaction. The first one is the
 LazyInitalization. I always have to reload the object in the methods that
 handle the form if I need to use some list of objects that have not been
 used when the page was rendered. 
 
 The second problem is that I want to put Transaction annotation or something
 like that so that I have transaction behavior instead of having every part
 of (what should be single transaction) commit independently.
 
 tnx for your help
 
 cheers
 
 --
 View this message in context: 
 http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713314.html
 Sent from the Tapestry - User mailing list archive at Nabble.com.
 
 -
 To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
 For additional commands, e-mail: users-h...@tapestry.apache.org
 


-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Transactions

2012-05-22 Thread bhorvat
 Say that you 
 load an object and that object has a list of objects in it, and you try to 
 access the list in the tml page with say the loop component. Now if you 
 dont 
 use the OpenSessionInViewFilter you should get an exception 
 (LazyInitalization). 

 Yes but only if the session is close. 

But isn't the idea of the OpenSessionInViewFilter to fix the problem that
session is closed before tml is starting to render. However even with it
everything works fine. So if I have a list of objects and I use it in a loop
component I dont get an exception, but I was under the impression that I
should get it and in order to fix the problem I should use the OSIVF


 However I dont get that exception, so I was wondering 
 (since most of the stuff for OSIVF is a bit old) is tapestry now handling 
 this itself (tapestry-hibernate that is) or am I miss understanding what 
 the 
 filter is used for in the first place? 
 
 No.

So tapestry now replaces the need for OSIVF, right? 

 Yes . Why is that unusable for you? The LazyInitalization is caused
 because 
 the entity is from another session (detached) and you are trying to access 
 a lazy property.

It would be nice so that I dont have to worry about this. With complex
object relationship I can never be too sure if I will get that exception
until I run. 

 CommitAfter is a nice example. But CommitAfter doesn't support nested 
 transactions. For this you'll need your own advice - or just don't call 
 @CommitAfter annotated methods in a transaction (other @CommitAfter 
 methods). 

So if I use spring then I dont need this CommitAfter. I will have to read
more about it :)

cheers and tnx for your help


--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713325.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Transactions

2012-05-22 Thread bhorvat

OpenSessionInViewFilter has nothing to do with detached entities, it only
keeps session open till view is rendered otherwise lazy loading will no
work. The filter is trying to solve it by always opening session in every
request and closing it at the end. Tapestry hibernate opens session only
when it is needed and closes it when thread is finished, it is how it should
be, but if you use spring hibernate + tx you need to use it there is no way
around it.
 
 --
 View this message in context:
 http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713314.html
 Sent from the Tapestry - User mailing list archive at Nabble.com.
 

So just to clarify the tapestry-hibernate now does the same thing as OSIVF
only better, right? Sorry for all the repetition but it is confusing a bit
:)

cheers

--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713326.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Transactions

2012-05-22 Thread Howard Lewis Ship
Tapestry's built-in Hibernate/JPA support is very close to OpenSessionInView.

It's lazier, I believe, than Springs. The Session is created on first
usage (via the magic of lazy proxies).

In any case, the transaction extends to the end of the request, and is
then aborted.

The challenge is never dealing with the entities during a single
request; its dealing with same entities across multiple requests.

With Tapestry, what gets persisted across requests is not a (detached)
entity instance, but instead the entity's id: as a (typically) numeric
string in a URL, in a hidden field, or in the HttpSession. On a later
request, the entity is reconstituted from the id: from Hibernate's
cache, or from the database.

The challenge here is that wizards can be difficult. In a wizard, you
want to render a series of pages (or even Ajax updates to a single
page) to modify different features of an entity, including adding,
modifying, and removing related entities (for example, the LineItems
in an Order).

In some models, you would detach the entity and store it in the
HttpSession for a while ... make changes, then reattach it to update
the database.  This is notoriously tricky in Hibernate, as
relationships from the entity to other entities can cause lazy
instantiation errors.

One of the reasons I'm very much liking document databases, such as
MongoDB, is that what would be encoded as a graph of entities in a ORM
becomes a single JSON document, that even has a natural string
representation for ease of transfer between server and client.

However, more than that, the direction the web is going (and where I
hope to bring Tapestry in 5.4) is that the basic HTTP/HTML Form
paradigm is outdated and should be abandoned except for the most
trivial cases.

For complex wizards, the UI should be dynamic on the client to
whatever degree is necessary, and the very last thing is to send a
package of updates to the server via Ajax. This is the approach you
see with client-side MVC frameworks such as Backbone.js, Spine,
SproutCore, etc.

So, what do you do today?  In some ways, you best bet is to create
DTOs that are not entities, and contain just the values to be edited
in your wizard. The DTOs are created from a Hibernate entity in one
transaction, can be updated across multiple transactions (persisted in
the HttpSession). At the end of the process, the DTOs can be used to
update the Entities.

It's not perfect; in a dynamic language environment such as Groovy or
Ruby you would just use maps for the DTOs, but in Java (and Tapestry)
you tend to create proper JavaBeans to let Tapestry leverage types and
annotations (though I would tend to create dumb objects with public
fields, rather than the whole getter/setter/private-field
shenanigans).

There is not one simple answer, but as in many situations, the guide
should be the content of your use case, rather than the schema of your
database.

On Tue, May 22, 2012 at 10:21 AM, bhorvat horvat.z.bo...@gmail.com wrote:

 OpenSessionInViewFilter has nothing to do with detached entities, it only
 keeps session open till view is rendered otherwise lazy loading will no
 work. The filter is trying to solve it by always opening session in every
 request and closing it at the end. Tapestry hibernate opens session only
 when it is needed and closes it when thread is finished, it is how it should
 be, but if you use spring hibernate + tx you need to use it there is no way
 around it.

 --
 View this message in context:
 http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713314.html
 Sent from the Tapestry - User mailing list archive at Nabble.com.


 So just to clarify the tapestry-hibernate now does the same thing as OSIVF
 only better, right? Sorry for all the repetition but it is confusing a bit
 :)

 cheers

 --
 View this message in context: 
 http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713326.html
 Sent from the Tapestry - User mailing list archive at Nabble.com.

 -
 To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
 For additional commands, e-mail: users-h...@tapestry.apache.org




-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Transactions

2012-05-22 Thread Thiago H. de Paula Figueiredo
On Tue, 22 May 2012 14:19:28 -0300, bhorvat horvat.z.bo...@gmail.com  
wrote:



So tapestry now replaces the need for OSIVF, right?


tapestry-hibernate and tapestry-jpa solve the same problem as OSIVF but  
without using a filter. Instead, it uses perthread services.



So if I use spring then I dont need this CommitAfter.


Yep. You'll use Spring's @Transactional and you'll ned the OSIVF.

--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor

Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Transactions

2012-05-22 Thread bhorvat
Hi Howard and tnx for joining in the fun. 

If you dont mind can you share a bit more light on what do you think in 5.4
will be in regards to this problem. How do you plan to move as you have said
it yourself in the direction in which the web is going. 


Howard Lewis Ship wrote
 
 However, more than that, the direction the web is going (and where I
 hope to bring Tapestry in 5.4) is that the basic HTTP/HTML Form
 paradigm is outdated and should be abandoned except for the most
 trivial cases.
 
 For complex wizards, the UI should be dynamic on the client to
 whatever degree is necessary, and the very last thing is to send a
 package of updates to the server via Ajax. This is the approach you
 see with client-side MVC frameworks such as Backbone.js, Spine,
 SproutCore, etc.
 
 So, what do you do today?  In some ways, you best bet is to create
 DTOs that are not entities, and contain just the values to be edited
 in your wizard. The DTOs are created from a Hibernate entity in one
 transaction, can be updated across multiple transactions (persisted in
 the HttpSession). At the end of the process, the DTOs can be used to
 update the Entities.
 


Do you have any plans to implement DTO's support or any way to fascilitate
the implementation of them in our application. The reason I am asking is
becase I would like to see what is in the future of tapestry so that I can
chose what is the best in that regards as well as my current needs.

Cheers and tnx

--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713329.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Transactions

2012-05-22 Thread bhorvat

Thiago H de Paula Figueiredo wrote
 
 On Tue, 22 May 2012 14:19:28 -0300, bhorvat lt;horvat.z.boris@gt;  
 wrote:
 
 So tapestry now replaces the need for OSIVF, right?
 
 tapestry-hibernate and tapestry-jpa solve the same problem as OSIVF but  
 without using a filter. Instead, it uses perthread services.
 
 So if I use spring then I dont need this CommitAfter.
 
 Yep. You'll use Spring's @Transactional and you'll ned the OSIVF.
 

Hi Thiago you are always very helpful I really appreciate that :)

So is there solution that implements the best of both worlds. Something that
would help me avoid OSIVF but have some transactional functionality that I
can put in some higher level method. So I have a method that says addItem
and in there I need to save and update a bunch of different entities. The
thing is I have tried puting @CommitAfter on methods like that but it didn't
work in cases I am trying to delete a bunch of entities. 

Cheers

--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713330.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Transactions

2012-05-22 Thread Thiago H. de Paula Figueiredo
On Tue, 22 May 2012 15:20:44 -0300, bhorvat horvat.z.bo...@gmail.com  
wrote:


thing is I have tried puting @CommitAfter on methods like that but it  
didn't work in cases I am trying to delete a bunch of entities.


Define 'didn't work'. From a transaction standpoint, updating, inserting  
and deleting is all the same thing: changes to the database.


--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor

Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Transactions

2012-05-22 Thread Lenny Primak
How about just using JEE transactions?  It's very easy and it's what the whole 
thing is built for. I am using these with great success in my not-so-small 
project. 



On May 22, 2012, at 2:20 PM, bhorvat horvat.z.bo...@gmail.com wrote:

 
 Thiago H de Paula Figueiredo wrote
 
 On Tue, 22 May 2012 14:19:28 -0300, bhorvat lt;horvat.z.boris@gt;  
 wrote:
 
 So tapestry now replaces the need for OSIVF, right?
 
 tapestry-hibernate and tapestry-jpa solve the same problem as OSIVF but  
 without using a filter. Instead, it uses perthread services.
 
 So if I use spring then I dont need this CommitAfter.
 
 Yep. You'll use Spring's @Transactional and you'll ned the OSIVF.
 
 
 Hi Thiago you are always very helpful I really appreciate that :)
 
 So is there solution that implements the best of both worlds. Something that
 would help me avoid OSIVF but have some transactional functionality that I
 can put in some higher level method. So I have a method that says addItem
 and in there I need to save and update a bunch of different entities. The
 thing is I have tried puting @CommitAfter on methods like that but it didn't
 work in cases I am trying to delete a bunch of entities. 
 
 Cheers
 
 --
 View this message in context: 
 http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713330.html
 Sent from the Tapestry - User mailing list archive at Nabble.com.
 
 -
 To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
 For additional commands, e-mail: users-h...@tapestry.apache.org
 

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Transactions

2012-05-22 Thread bhorvat
So currently I have a method addItem and removeItem in in there I create
couple of entities and remove a couple. Now in those methods I have call to
services that only handle single entities (it is just a hibernate CRUD), and
this works fine because on the interface of them I have @CommitAfter. 

However when I removed the annotation and moved it to the addItem and
removeItem the addItem works - it create new entities in the DB, but
removeItem does not remove them. This was my idea of create a transaction
layer since everything that is to be commited is done at once.



--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p571.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Transactions

2012-05-22 Thread bhorvat
With JEE transaction I would have to handle everything manually? Like so 

UserTransaction transaction = (UserTransaction)new
InitialContext().lookup(java:comp/UserTransaction);
transaction.begin();
EntityManager em = getEntityManager();
Employee employee = em.find(Employee.class, id);
employee.setSalary(employee.getSalary() + 1000);
transaction.commit();

http://en.wikibooks.org/wiki/Java_Persistence/Transactions

--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713334.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Transactions

2012-05-22 Thread Lenny Primak
No. You can use BMP (Bean-Managed Persistence). 
The commit happens automatically at the end of your business method and nested 
and XA transactions are supported via annotations.  



On May 22, 2012, at 2:36 PM, bhorvat horvat.z.bo...@gmail.com wrote:

 With JEE transaction I would have to handle everything manually? Like so 
 
 UserTransaction transaction = (UserTransaction)new
 InitialContext().lookup(java:comp/UserTransaction);
 transaction.begin();
 EntityManager em = getEntityManager();
 Employee employee = em.find(Employee.class, id);
 employee.setSalary(employee.getSalary() + 1000);
 transaction.commit();
 
 http://en.wikibooks.org/wiki/Java_Persistence/Transactions
 
 --
 View this message in context: 
 http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713334.html
 Sent from the Tapestry - User mailing list archive at Nabble.com.
 
 -
 To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
 For additional commands, e-mail: users-h...@tapestry.apache.org
 

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Transactions

2012-05-22 Thread Lenny Primak
Sorry, not what I meant to say at all.

You can use CMT (Container-Managed Transactions)
The commit happens automatically at the end of your business method and nested 
and XA transactions are supported via annotations.  

On May 22, 2012, at 2:41 PM, Lenny Primak wrote:

 No. You can use BMP (Bean-Managed Persistence). 
 The commit happens automatically at the end of your business method and 
 nested and XA transactions are supported via annotations.  
 
 
 
 On May 22, 2012, at 2:36 PM, bhorvat horvat.z.bo...@gmail.com wrote:
 
 With JEE transaction I would have to handle everything manually? Like so 
 
 UserTransaction transaction = (UserTransaction)new
 InitialContext().lookup(java:comp/UserTransaction);
 transaction.begin();
 EntityManager em = getEntityManager();
 Employee employee = em.find(Employee.class, id);
 employee.setSalary(employee.getSalary() + 1000);
 transaction.commit();
 
 http://en.wikibooks.org/wiki/Java_Persistence/Transactions
 
 --
 View this message in context: 
 http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713334.html
 Sent from the Tapestry - User mailing list archive at Nabble.com.
 
 -
 To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
 For additional commands, e-mail: users-h...@tapestry.apache.org
 
 
 -
 To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
 For additional commands, e-mail: users-h...@tapestry.apache.org
 


-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Transactions

2012-05-22 Thread bhorvat
I have been reading up a bit on all of this transactions (as I am not that
familiar with it yet :) ), and the last thing that I have read is
http://static.springsource.org/spring/docs/2.0.x/reference/transaction.html

It seams to me that transactions that offer EJB like CMT are a bit more
heavyweight then it is needed. So I think that I would like to avoid all
them and try to use the spring instead. However I do like the fact that
Hibernate implementation of OSIVF is a bit more lightweight. 

Can someone show some good example of implementing all of this and merging
it with tapestry? I am trying to search but nothing really nice so far, and
someone who is more experience can know some good results. 

Also there was mention here that OSIVF should be avoided since it is an
antipatern, can someone put some good words for the OSIVF and their
experience with all of this?

cheers and tnx all

--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713339.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Transactions

2012-05-22 Thread Lenny Primak
I would not use spring in any new projects. Just my opinion though. 

On May 22, 2012, at 4:59 PM, bhorvat horvat.z.bo...@gmail.com wrote:

 I have been reading up a bit on all of this transactions (as I am not that
 familiar with it yet :) ), and the last thing that I have read is
 http://static.springsource.org/spring/docs/2.0.x/reference/transaction.html
 
 It seams to me that transactions that offer EJB like CMT are a bit more
 heavyweight then it is needed. So I think that I would like to avoid all
 them and try to use the spring instead. However I do like the fact that
 Hibernate implementation of OSIVF is a bit more lightweight. 
 
 Can someone show some good example of implementing all of this and merging
 it with tapestry? I am trying to search but nothing really nice so far, and
 someone who is more experience can know some good results. 
 
 Also there was mention here that OSIVF should be avoided since it is an
 antipatern, can someone put some good words for the OSIVF and their
 experience with all of this?
 
 cheers and tnx all
 
 --
 View this message in context: 
 http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713339.html
 Sent from the Tapestry - User mailing list archive at Nabble.com.
 
 -
 To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
 For additional commands, e-mail: users-h...@tapestry.apache.org
 

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Transactions

2012-05-22 Thread bhorvat
How so? It was my impression that spring is more lightweight then EJB and all
that come with it so it is less dependent, am I wrong? 

tnx

--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713341.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Transactions

2012-05-22 Thread Lenny Primak
This is not a topic for this mailing list. There is plenty of other discussions 
about this elsewhere on the Internet. 
Suffice it to say that after doing extensive research I came to a confusion 
that JEE is the way to go for back end services with transactions and tapestry 
for the web front end. 

On May 22, 2012, at 5:05 PM, bhorvat horvat.z.bo...@gmail.com wrote:

 How so? It was my impression that spring is more lightweight then EJB and all
 that come with it so it is less dependent, am I wrong? 
 
 tnx
 
 --
 View this message in context: 
 http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713341.html
 Sent from the Tapestry - User mailing list archive at Nabble.com.
 
 -
 To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
 For additional commands, e-mail: users-h...@tapestry.apache.org
 

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Transactions

2012-05-22 Thread bhorvat
You are right I wont pollute this mail thread with that anymore, I will try
to do a bit more research on one vs the other.

But in the mean time if anyone has any suggestion and nice links about
spring-transactions and OSIVF please share it will be of great help

cheers

--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Tapestry-Transactions-tp5713299p5713343.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org