On 6/23/07, Robert . <[EMAIL PROTECTED]> wrote:
On 6/23/07, Flemming Boller <[EMAIL PROTECTED]> wrote:
>
> On 6/23/07, Robert . <[EMAIL PROTECTED] > wrote:
>
> > One thing I am struggling with is where I should put my DAO's and data
> >
> > services. I know about the @SpringBean annotation for components, but
> > how should I use those in classes such as DetachableXXXModel? Should
> > I pass the DAO's I need to that class or should I put DAO's in the
> > application object (like Pro Wicket examples do)?
>
>
> There is no silverbullet here. Each solution has its drawbacks. However
> the solution I have come to best like is only using the @SpringBean in
> pages, and then pass on the springbean as argument to where every it is
> needed. That way it is also more clearly seen in the page where the service
> is used.
>
I'm curious when this is simpler that accessing the DAOs from the
application object. I find it annoying so far that I find out that I need a
certain DAO in my DetachableXXXModel, and then, for example, have to pass it
from the page to the XXXDataProvider, save a reference there, and in the
model method pass it to the DetachableXXXModel.
there is nothing wrong with doing this
class PersonModel extends LoadableDetachableModel {
@SpringBean
private PersonDao dao;
private final long id;
public PersonModel(long id) {
this.id=id;
InjectorHolder.getInjector().inject(this);
}
...
}
or use springbean in panels, etc. that will save you from the pain of having
to pass all the extra arguments around if you dont mind a bit tighter
coupling in your code.
Is there a good Wicket example project I can look at, besides phonebook,
> > that uses Spring and Hibernate? I am interested in the right set-up.
>
>
> You could also look at the Databinder project. It includes some nice
> examples too.
>
Ok thanks!
I also have some questions about OpenSessionInViewFilter, which probably
> > are off-topic, but hope someone wants to help anyway.
> >
> > There seems to be quite some disagreements about whether using
> > OpenSessionInViewFilter is a good thing or not. What does the Wicket
> > team/users
> > think about it?
>
>
> I have also used OSIVF on a project. And you really have to be carefull
> here. Hibernate has some nasty exceptions that easily will be thrown at you.
> Especially Lazyexception session closed or... object with same id is already
> loaded in session
>
Unfortunately I do not know what to be careful for yet :)
i have managed to avoid any object with same id and session closed
exceptions without trying so far. maybe im just lucky :)
I came to the conclusion that is was much easier to copy you hibernate
> objects into viewbeans which is designed with wicket in mind. So above the
> service layer you have view bean. And under the service layer you have
> hibernateobjects (domain objects). I would be happy to hear others comments
> on this one.
>
Do you have an example for this? It's difficult to think of what those
viewbeans are. They don't have associations?
You know the answer(s) to the section below?
If I understand correctly, and please correct me if I'm wrong,
> > by using the OpenSessionInViewFilter you get a new transaction at the
> > start
> > of every request, which commits or rollbacks at the end.
> > This is so that lazy associations, which are accessed outside explicit
> > transactions,
> > such as in Wicket Page classes, are initialized and don't throw an
> > exception.
>
> So what kind of transaction exactly is created by the
> > OpenSessionInViewFilter?
> > (propagation, isolation?)
> > Can I use it only for reading?
>
>
i am not sure a transaction is created. i think what happens is that the
same session is used for all transactions (unless you set propogation:
requires new) rather then a session-per-transaction pattern. this is really
the only way to get hibernate's lazy-loading to work in the view layer.
-igor
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user