You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by mirlan <mi...@yahoo.com> on 2009/10/29 12:04:00 UTC
Error in integrating Tapestry5 with Hibernate.
Hi,
I am trying to integrate tapestry5 with Hibernate. I have done all steps which are defined in http://wiki.apache.org/tapestry/Tapestry5HowToUseTapestryHibernate .
It is compiling without errors but when i run HbAction page it gives me exceptions.
org.example.example1.web.pages.HbAction.onAction(HbAction.java:29)
org.example.example1.web.services.AppModule$1.service(AppModule.java:90)
Please help if you have any ideas?
Thank you,
my codes are as bellow:
Hello.java
package org.example.example1.web.entities;
/**
*
* @author mirlan
*/
import javax.persistence.*;
@Entity
@Table(name="hello")
public class Hello {
@Id
@GeneratedValue
private long id;
private String message;
public long getId() { return id;}
public void setId(long id) { this.id = id; }
public String getMessage() { return message;}
public void setMessage(String message) { this.message = message;}
}
HbAction.java
import java.util.List;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.example.example1.web.entities.Hello;
import org.hibernate.Session;
public class HbAction {
@Inject
private Session _session;
private Hello current;
public void onAction() {
Hello h = new Hello();
h.setMessage("Hello World");
_session.save(h);
_session.close();
}
public List getList() {
return _session.createCriteria(Hello.class).list();
}
public Hello getCurrent() {
return current;
}
public void setCurrent(Hello current) {
this.current = current;
}
}
AppModule.java
package org.example.example1.web.services;
import java.io.IOException;
import org.apache.tapestry5.*;
import org.apache.tapestry5.ioc.MappedConfiguration;
import org.apache.tapestry5.ioc.OrderedConfiguration;
import org.apache.tapestry5.ioc.ServiceBinder;
import org.apache.tapestry5.ioc.annotations.Local;
import org.apache.tapestry5.services.Request;
import org.apache.tapestry5.services.RequestFilter;
import org.apache.tapestry5.services.RequestHandler;
import org.apache.tapestry5.services.Response;
import org.slf4j.Logger;
/**
* This module is automatically included as part of the Tapestry IoC Registry, it's a good place to
* configure and extend Tapestry, or to place your own service definitions.
*/
public class AppModule
{
public static void bind(ServiceBinder binder)
{
// binder.bind(MyServiceInterface.class, MyServiceImpl.class);
// Make bind() calls on the binder object to define most IoC services.
// Use service builder methods (example below) when the implementation
// is provided inline, or requires more initialization than simply
// invoking the constructor.
}
public static void contributeApplicationDefaults(
MappedConfiguration<String, String> configuration)
{
// Contributions to ApplicationDefaults will override any contributions to
// FactoryDefaults (with the same key). Here we're restricting the supported
// locales to just "en" (English). As you add localised message catalogs and other assets,
// you can extend this list of locales (it's a comma separated series of locale names;
// the first locale name is the default when there's no reasonable match).
configuration.add(SymbolConstants.SUPPORTED_LOCALES, "en");
// The factory default is true but during the early stages of an application
// overriding to false is a good idea. In addition, this is often overridden
// on the command line as -Dtapestry.production-mode=false
configuration.add(SymbolConstants.PRODUCTION_MODE, "false");
// The application version number is incorprated into URLs for some
// assets. Web browsers will cache assets because of the far future expires
// header. If existing assets are changed, the version number should also
// change, to force the browser to download new versions.
configuration.add(SymbolConstants.APPLICATION_VERSION, "1.0-SNAPSHOT");
}
/**
* This is a service definition, the service will be named "TimingFilter". The interface,
* RequestFilter, is used within the RequestHandler service pipeline, which is built from the
* RequestHandler service configuration. Tapestry IoC is responsible for passing in an
* appropriate Logger instance. Requests for static resources are handled at a higher level, so
* this filter will only be invoked for Tapestry related requests.
*
* <p>
* Service builder methods are useful when the implementation is inline as an inner class
* (as here) or require some other kind of special initialization. In most cases,
* use the static bind() method instead.
*
* <p>
* If this method was named "build", then the service id would be taken from the
* service interface and would be "RequestFilter". Since Tapestry already defines
* a service named "RequestFilter" we use an explicit service id that we can reference
* inside the contribution method.
*/
public RequestFilter buildTimingFilter(final Logger log)
{
return new RequestFilter()
{
public boolean service(Request request, Response response, RequestHandler handler)
throws IOException
{
long startTime = System.currentTimeMillis();
try
{
// The responsibility of a filter is to invoke the corresponding method
// in the handler. When you chain multiple filters together, each filter
// received a handler that is a bridge to the next filter.
return handler.service(request, response);
}
finally
{
long elapsed = System.currentTimeMillis() - startTime;
log.info(String.format("Request time: %d ms", elapsed));
}
}
};
}
/**
* This is a contribution to the RequestHandler service configuration. This is how we extend
* Tapestry using the timing filter. A common use for this kind of filter is transaction
* management or security. The @Local annotation selects the desired service by type, but only
* from the same module. Without @Local, there would be an error due to the other service(s)
* that implement RequestFilter (defined in other modules).
*/
public void contributeRequestHandler(OrderedConfiguration<RequestFilter> configuration,
@Local
RequestFilter filter)
{
// Each contribution to an ordered configuration has a name, When necessary, you may
// set constraints to precisely control the invocation order of the contributed filter
// within the pipeline.
configuration.add("Timing", filter);
}
}
Re: Error in integrating Tapestry5 with Hibernate.
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Thu, 29 Oct 2009 09:04:00 -0200, mirlan <mi...@yahoo.com> escreveu:
> Hi,
Hi!
> It is compiling without errors but when i run HbAction page it gives me
> exceptions.
Without the stack traces, it's nearly impossible to help you.
--
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Error in integrating Tapestry5 with Hibernate.
Posted by Ulrich Stärk <ul...@spielviel.de>.
First: Don't hijack other people's thread. Create a new one (don't hit reply and just change the topic).
Second: Read the wiki article again and compare it with what you got.
Uli
Am 29.10.2009 12:04 schrieb mirlan:
> Hi,
> I am trying to integrate tapestry5 with Hibernate. I have done all steps which are defined in http://wiki.apache.org/tapestry/Tapestry5HowToUseTapestryHibernate .
> It is compiling without errors but when i run HbAction page it gives me exceptions.
>
> org.example.example1.web.pages.HbAction.onAction(HbAction.java:29)
>
> org.example.example1.web.services.AppModule$1.service(AppModule.java:90)
>
>
> Please help if you have any ideas?
>
> Thank you,
> my codes are as bellow:
>
> Hello.java
>
> package org.example.example1.web.entities;
>
> /**
> *
> * @author mirlan
> */
> import javax.persistence.*;
>
> @Entity
> @Table(name="hello")
> public class Hello {
>
> @Id
> @GeneratedValue
> private long id;
> private String message;
>
> public long getId() { return id;}
>
> public void setId(long id) { this.id = id; }
>
> public String getMessage() { return message;}
>
> public void setMessage(String message) { this.message = message;}
> }
>
> HbAction.java
>
>
> import java.util.List;
>
> import org.apache.tapestry5.ioc.annotations.Inject;
> import org.example.example1.web.entities.Hello;
> import org.hibernate.Session;
>
> public class HbAction {
>
> @Inject
> private Session _session;
>
> private Hello current;
>
> public void onAction() {
> Hello h = new Hello();
> h.setMessage("Hello World");
> _session.save(h);
> _session.close();
> }
>
> public List getList() {
> return _session.createCriteria(Hello.class).list();
> }
>
> public Hello getCurrent() {
> return current;
> }
>
> public void setCurrent(Hello current) {
> this.current = current;
> }
>
> }
>
> AppModule.java
> package org.example.example1.web.services;
>
> import java.io.IOException;
>
> import org.apache.tapestry5.*;
> import org.apache.tapestry5.ioc.MappedConfiguration;
> import org.apache.tapestry5.ioc.OrderedConfiguration;
> import org.apache.tapestry5.ioc.ServiceBinder;
> import org.apache.tapestry5.ioc.annotations.Local;
> import org.apache.tapestry5.services.Request;
> import org.apache.tapestry5.services.RequestFilter;
> import org.apache.tapestry5.services.RequestHandler;
> import org.apache.tapestry5.services.Response;
> import org.slf4j.Logger;
>
> /**
> * This module is automatically included as part of the Tapestry IoC Registry, it's a good place to
> * configure and extend Tapestry, or to place your own service definitions.
> */
> public class AppModule
> {
> public static void bind(ServiceBinder binder)
> {
> // binder.bind(MyServiceInterface.class, MyServiceImpl.class);
>
> // Make bind() calls on the binder object to define most IoC services.
> // Use service builder methods (example below) when the implementation
> // is provided inline, or requires more initialization than simply
> // invoking the constructor.
> }
>
>
> public static void contributeApplicationDefaults(
> MappedConfiguration<String, String> configuration)
> {
> // Contributions to ApplicationDefaults will override any contributions to
> // FactoryDefaults (with the same key). Here we're restricting the supported
> // locales to just "en" (English). As you add localised message catalogs and other assets,
> // you can extend this list of locales (it's a comma separated series of locale names;
> // the first locale name is the default when there's no reasonable match).
>
> configuration.add(SymbolConstants.SUPPORTED_LOCALES, "en");
>
> // The factory default is true but during the early stages of an application
> // overriding to false is a good idea. In addition, this is often overridden
> // on the command line as -Dtapestry.production-mode=false
> configuration.add(SymbolConstants.PRODUCTION_MODE, "false");
>
> // The application version number is incorprated into URLs for some
> // assets. Web browsers will cache assets because of the far future expires
> // header. If existing assets are changed, the version number should also
> // change, to force the browser to download new versions.
> configuration.add(SymbolConstants.APPLICATION_VERSION, "1.0-SNAPSHOT");
> }
>
>
> /**
> * This is a service definition, the service will be named "TimingFilter". The interface,
> * RequestFilter, is used within the RequestHandler service pipeline, which is built from the
> * RequestHandler service configuration. Tapestry IoC is responsible for passing in an
> * appropriate Logger instance. Requests for static resources are handled at a higher level, so
> * this filter will only be invoked for Tapestry related requests.
> *
> * <p>
> * Service builder methods are useful when the implementation is inline as an inner class
> * (as here) or require some other kind of special initialization. In most cases,
> * use the static bind() method instead.
> *
> * <p>
> * If this method was named "build", then the service id would be taken from the
> * service interface and would be "RequestFilter". Since Tapestry already defines
> * a service named "RequestFilter" we use an explicit service id that we can reference
> * inside the contribution method.
> */
> public RequestFilter buildTimingFilter(final Logger log)
> {
> return new RequestFilter()
> {
> public boolean service(Request request, Response response, RequestHandler handler)
> throws IOException
> {
> long startTime = System.currentTimeMillis();
>
> try
> {
> // The responsibility of a filter is to invoke the corresponding method
> // in the handler. When you chain multiple filters together, each filter
> // received a handler that is a bridge to the next filter.
>
> return handler.service(request, response);
> }
> finally
> {
> long elapsed = System.currentTimeMillis() - startTime;
>
> log.info(String.format("Request time: %d ms", elapsed));
> }
> }
> };
> }
>
> /**
> * This is a contribution to the RequestHandler service configuration. This is how we extend
> * Tapestry using the timing filter. A common use for this kind of filter is transaction
> * management or security. The @Local annotation selects the desired service by type, but only
> * from the same module. Without @Local, there would be an error due to the other service(s)
> * that implement RequestFilter (defined in other modules).
> */
> public void contributeRequestHandler(OrderedConfiguration<RequestFilter> configuration,
> @Local
> RequestFilter filter)
> {
> // Each contribution to an ordered configuration has a name, When necessary, you may
> // set constraints to precisely control the invocation order of the contributed filter
> // within the pipeline.
>
> configuration.add("Timing", filter);
> }
> }
>
>
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org