Re: Wicket + Guice + Warp-persist + Hibernate

2009-10-06 Thread nino martinez wael
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-nameMyApp/display-name

  context-param

param-nameconfiguration/param-name

param-valuedevelopment/param-value

  /context-param



 !-- Warp Filter --

  filter

filter-namewarpSessionFilter/filter-name


 filter-classcom.wideplay.warp.hibernate.SessionPerRequestFilter/filte
 r-class

/filter



filter-mapping

filter-namewarpSessionFilter/filter-name

url-pattern/*/url-pattern

/filter-mapping

 !-- Warp Filter --



  filter

filter-namewicket.filter/filter-name


 filter-classorg.apache.wicket.protocol.http.WicketFilter/filter-class
 

init-param

  param-nameapplicationClassName/param-name

  param-valuecom.myapp.WicketApplication/param-value

/init-param

  /filter

  filter-mapping

filter-namewicket.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

ProviderSession hibernateSession;




RE: Wicket + Guice + Warp-persist + Hibernate

2009-10-06 Thread Jeffrey Schneller
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-nameMyApp/display-name

  context-param

param-nameconfiguration/param-name

param-valuedevelopment/param-value

  /context-param



 !-- Warp Filter --

  filter

filter-namewarpSessionFilter/filter-name



filter-classcom.wideplay.warp.hibernate.SessionPerRequestFilter/filte
 r-class

/filter



filter-mapping

filter-namewarpSessionFilter/filter-name

url-pattern/*/url-pattern

/filter-mapping

 !-- Warp Filter --



  filter

filter-namewicket.filter/filter-name



filter-classorg.apache.wicket.protocol.http.WicketFilter/filter-class
 

init-param

  param-nameapplicationClassName/param-name

  param-valuecom.myapp.WicketApplication/param-value

/init-param

  /filter

  filter-mapping

Re: Wicket + Guice + Warp-persist + Hibernate

2009-10-06 Thread nino martinez wael
Hmm seems like your Guice arent booted? Are you using the Guice integration
from wicket as well? Does  service.start() etc give an exception etc?


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

 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-nameMyApp/display-name
 
   context-param
 
 param-nameconfiguration/param-name
 
 param-valuedevelopment/param-value
 
   /context-param
 
 
 
  !-- Warp Filter --
 
   filter
 
 filter-namewarpSessionFilter/filter-name
 
 
 
 filter-classcom.wideplay.warp.hibernate.SessionPerRequestFilter/filte
  r-class
 
 /filter
 
 
 
 filter-mapping