You need to work on your AvailabilityLocator implementation. Your
implementation of getVersion() is returning null, which is exactly
what the error message is telling you. Also, your implementation of
find() isn't doing what it should, getIdType() is returning null
(should return Long.class in this case), and getId() is converting an
int to a String to a Long which is a pretty roundabout way of getting
that result.

I haven't looked for simple examples, but I found that I was able to
figure everything out by experimenting in a sample project of my own.
I first started with EntityProxy as it was originally created (no
locators), then I added locators, service locators, and finally
introduced ValueProxy. When it comes to learning something like this,
picking it up and playing with it is often a good way to go.

-- Brian


On Wed, May 18, 2011 at 3:07 PM, Alexander Orlov
<[email protected]> wrote:
> Dev Mode initialized. Startup URL:
> http://127.0.0.1:8888/?gwt.codesvr=127.0.0.1:9997
> May 18, 2011 5:41:12 PM
> com.google.web.bindery.requestfactory.server.RequestFactoryServlet
> doPost
> SEVERE: Unexpected error
> com.google.web.bindery.requestfactory.server.UnexpectedException: The
> persisted entity with id 0 has a null version
> [...]
> [ERROR] 500 - POST /gwtRequest (127.0.0.1) 1420 bytes
> #########################
>
> ...is what I get.
>
> my web.xml:
>
>    <servlet>
>        <servlet-name>requestFactoryServlet</servlet-name>
>        <servlet-
> class>com.google.web.bindery.requestfactory.server.RequestFactoryServlet</
> servlet-class>
>    </servlet>
>
>    <servlet-mapping>
>        <servlet-name>requestFactoryServlet</servlet-name>
>        <url-pattern>/gwtRequest</url-pattern>
>    </servlet-mapping>
>
> my server/AvailabilityLocator.java:
>
> import com.google.web.bindery.requestfactory.shared.Locator;
> import dp.verp.model.Availability;
>
> public class AvailabilityLocator extends Locator<Availability, Long> {
>    @Override
>    public Availability create(Class<? extends Availability> aClass) {
>        return new Availability();
>    }
>
>    @Override
>    public Availability find(Class<? extends Availability> aClass,
> Long aLong) {
>        return new Availability();
>    }
>
>    @Override
>    public Class<Availability> getDomainType() {
>        return null;
>    }
>
>    @Override
>    public Long getId(Availability availability) {
>        return Long.parseLong(String.valueOf(availability.getId()));
>    }
>
>    @Override
>    public Class<Long> getIdType() {
>        return null;
>    }
>
>    @Override
>    public Object getVersion(Availability availability) {
>        return null;
>    }
> }
>
> my server/MyServiceLocator:
>
> import com.google.web.bindery.requestfactory.shared.ServiceLocator;
>
> public class MyServiceLocator implements ServiceLocator {
>    /**
>     * Returns an instance of the service object.
>     *
>     * @param clazz the requested type of service object
>     * @return an instance of the service object
>     */
>    @Override
>    public Object getInstance(Class<?> clazz) {
>        try {
>            return clazz.newInstance();
>        } catch (InstantiationException e) {
>            throw new RuntimeException(e);
>        } catch (IllegalAccessException e) {
>            throw new RuntimeException(e);
>        }
>    }
> }
>
> my shared/AvailabilityProxy.java:
>
> import com.google.web.bindery.requestfactory.shared.EntityProxy;
> import com.google.web.bindery.requestfactory.shared.ProxyFor;
> import dp.verp.model.Availability;
> import dp.verp.view.availability.server.AvailabilityLocator;
>
> @ProxyFor(value = Availability.class, locator =
> AvailabilityLocator.class)
> public interface AvailabilityProxy extends EntityProxy {
>    int getId();
>
>    void setSchedule(String schedule);
>
>    String getSchedule();
> }
>
> my shard/AvailabilityRequest:
>
> import com.google.web.bindery.requestfactory.shared.InstanceRequest;
> import com.google.web.bindery.requestfactory.shared.Request;
> import com.google.web.bindery.requestfactory.shared.RequestContext;
> import com.google.web.bindery.requestfactory.shared.Service;
> import dp.verp.model.Availability;
> import dp.verp.view.availability.server.MyServiceLocator;
>
> @Service(value = Availability.class, locator = MyServiceLocator.class)
> public interface AvailabilityRequest extends RequestContext {
>    InstanceRequest<AvailabilityProxy, Void> persist();
> }
>
> my shared/AvailabilityRequestFactory.java:
>
> import com.google.web.bindery.requestfactory.shared.InstanceRequest;
> import com.google.web.bindery.requestfactory.shared.RequestContext;
> import com.google.web.bindery.requestfactory.shared.RequestFactory;
> import com.google.web.bindery.requestfactory.shared.Service;
> import dp.verp.model.Availability;
>
> public interface AvailabilityRequestFactory extends RequestFactory {
>    /**
>     * Source of request objects for the Person class.
>     */
>    @Service(Availability.class)
>    interface PersonRequest extends RequestContext {
>        InstanceRequest<AvailabilityProxy, Void> persist();
>    }
>
>    AvailabilityRequest availabilityRequest();
> }
>
> my model/Availability.java:
>
> @Entity
> public class Availability {
>    @Id
>    private int id;
>    private String schedule;
>
>  public void persist() {
>    EntityManager em = Database.getEntityManager();
>    try {
>        em.persist(this);
>    } finally {
>      em.close();
>    }
>  }
>    public int getId() {
>        return id;
>    }
>
>    public String getSchedule() {
>        return schedule;
>    }
>
>    public void setSchedule(String schedule) {
>        this.schedule = schedule;
>    }
> }
>
> ################
>
> And here is my call from the presenter class:
>
>        EventBus eventBus = new SimpleEventBus();
>        AvailabilityRequestFactory requestFactory =
> GWT.create(AvailabilityRequestFactory.class);
>        requestFactory.initialize(eventBus);
>
>        AvailabilityRequest request =
> requestFactory.availabilityRequest();
>        AvailabilityProxy availabilityProxy =
> request.create(AvailabilityProxy.class);
>        Request<Void> createReq =
> request.persist().using(availabilityProxy);
>
>
>        createReq.fire(new Receiver<Void>() {
>            @Override
>            public void onSuccess(Void response) {
>
>            }
>        });
>
> Btw does anybody know a working&minimalistic example that implements
> the RequestFactory paradigm?
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Google Web Toolkit" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/google-web-toolkit?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to