I haven't even got to the detachable models part of it yet.  A simple
query to the db does not work as it does not have the session injected.

-----Original Message-----
From: nino martinez wael [mailto:nino.martinez.w...@gmail.com] 
Sent: Tuesday, October 06, 2009 6:51 AM
To: users@wicket.apache.org
Subject: Re: Wicket + Guice + Warp-persist + Hibernate

How does the code that are using it look like? Are you using detachable
models etc?

2009/10/6 Jeffrey Schneller <jeffrey.schnel...@envisa.com>

> So I took the plunge and tried to implement Guice + Warp Persist to
> solve my lazy loading issues.  I know I may not have it all figured
out
> with regards to lazy loading but I can't even get simple data access
to
> work now.  Sorry for all the questions and issues.  Can anyone provide
> some insight on what is wrong or what I am missing. The Hibernate
> configuration succeeds in the getModule() method.
>
>
>
> Thanks.
>
>
>
> Code is below:
>
>
>
>
>
> My Web Application
>
>
>
> public class WicketApplication extends WebApplication {
>
>
>
>                private PersistenceService service;
>
>
>
>                public WicketApplication() {
>
>                }
>
>
>
>                @Override
>
>                public Class<? extends Page> getHomePage() {
>
>                                return Home.class;
>
>                }
>
>
>
>                @Override
>
>                public Session newSession(Request request, Response
> response) {
>
>                                return new MySession(request);
>
>                }
>
>
>
>                @Override
>
>                protected void init() {
>
>
>
>                                Injector injector =
> Guice.createInjector(PersistenceService.usingHibernate()
>
>
> .across(UnitOfWork.REQUEST).transactedWith(
>
>
> TransactionStrategy.LOCAL).buildModule(),
>
>
> getModule());
>
>
>
>                                addComponentInstantiationListener(new
> GuiceComponentInjector(this, injector));
>
>
>
>                                service =
> injector.getInstance(PersistenceService.class);
>
>                                service.start();
>
>                                injector.injectMembers(this);
>
>
>
>                }
>
>
>
>    private Module getModule() {
>
>        return new Module() {
>
>            public void configure(Binder binder) {
>
>
>
>                                // default values from development
>
>                                String connectionUrl = "<the url>";
>
>                                String username = "<the username>";
>
>                                String password = <the password>";
>
>
>
>                                try {
>
>                                                InitialContext context
=
> new InitialContext();
>
>                                                connectionUrl =
(String)
> context.lookup("java:comp/env/hibernate.connection.url");
>
>                                                username = (String)
> context.lookup("java:comp/env/hibernate.connection.username");
>
>                                                password = (String)
> context.lookup("java:comp/env/hibernate.connection.password");
>
>                                } catch (NamingException e1) {
>
>                                                // TODO Auto-generated
> catch block
>
>                                                e1.printStackTrace();
>
>                                }
>
>
>
>                                // annotation and xml
>
>                                final AnnotationConfiguration config =
> new AnnotationConfiguration().configure();
>
>
> config.setProperty("hibernate.connection.url", connectionUrl);
>
>
> config.setProperty("hibernate.connection.username", username);
>
>
> config.setProperty("hibernate.connection.password", password);
>
>
> config.setProperty("hibernate.current_session_context_class",
> "managed");
>
>
>
>
>
>                binder.bind(Configuration.class).toInstance(config);
>
>            }
>
>        };
>
>    }
>
> }
>
>
>
> My web.xml
>
>
>
> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> xmlns="http://java.sun.com/xml/ns/javaee";
> xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd";
> xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
> http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"; id="WebApp_ID"
> version="2.5">
>
>  <display-name>MyApp</display-name>
>
>  <context-param>
>
>    <param-name>configuration</param-name>
>
>    <param-value>development</param-value>
>
>  </context-param>
>
>
>
> <!-- Warp Filter -->
>
>          <filter>
>
>                <filter-name>warpSessionFilter</filter-name>
>
>
>
<filter-class>com.wideplay.warp.hibernate.SessionPerRequestFilter</filte
> r-class>
>
>        </filter>
>
>
>
>        <filter-mapping>
>
>                <filter-name>warpSessionFilter</filter-name>
>
>                <url-pattern>/*</url-pattern>
>
>        </filter-mapping>
>
> <!-- Warp Filter -->
>
>
>
>  <filter>
>
>    <filter-name>wicket.filter</filter-name>
>
>
>
<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class
> >
>
>    <init-param>
>
>      <param-name>applicationClassName</param-name>
>
>      <param-value>com.myapp.WicketApplication</param-value>
>
>    </init-param>
>
>  </filter>
>
>  <filter-mapping>
>
>    <filter-name>wicket.filter</filter-name>
>
>    <url-pattern>/*</url-pattern>
>
>  </filter-mapping>
>
> </web-app>
>
>
>
>
>
> And my Hibernate Base Generic DAO:
>
>
>
> public abstract class HibernateGenericDao implements GenericDao {
>
>
>
>                private final Class persistentClass;
>
>
>
>                @Inject
>
>                Provider<Session> hibernateSession;
>
>
>
>                public HibernateGenericDao(Class persistentClass) {
>
>                                this.persistentClass = persistentClass;
>
>                }
>
>
>
>                @Override
>
>                public List<Object> findAll() {
>
>                                Session session =
> hibernateSession.get();
>
>                                List objects = null;
>
>                                Transaction tx = null;
>
>                                try {
>
>                                                tx =
> session.beginTransaction();
>
>                                                Criteria criteria =
> session.createCriteria(persistentClass);
>
>                                                objects =
> criteria.list();
>
>                                                tx.commit();
>
>                                                return objects;
>
>                                } catch (HibernateException e) {
>
>                                                if (tx != null)
> tx.rollback();
>
>                                                throw e;
>
>                                } finally {
>
>                                }
>
>                }
>
> }
>
>

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

Reply via email to