I use the same pattern explained here with JPA/Spring for the Entity Locator
http://groups.google.com/group/google-web-toolkit/browse_thread/thread/20ea2aea53aa29d3/687ff2df944c483c
public class MyDataLocator extends Locator<MyData, Long> {
private MyRepository getRepository() {
HttpServletRequest request =
RequestFactoryServlet.getThreadLocalRequest();
ApplicationContext context =
WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
MyRepository repository = context.getBean(MyRepository.class);
return repository;
}
@Override
public MyData create(Class<? extends MyData> clazz) {
MyRepository repository = getRepository();
repository.persist(new MyData());
*return null;*
}
@Override
public MyData find(Class<? extends MyData> clazz, Long id) {
MyRepository myRepository = getRepository();
MyData entity = myRepository.findByPrimaryKey(id);
return entity;
}
@Override
public Class<MyData> getDomainType() {
return MyData.class;
}
@Override
public Long getId(MyData domainObject) {
return domainObject.getId();
}
@Override
public Class<Long> getIdType() {
return Long.class;
}
@Override
public Long getVersion(MyData domainObject) {
return domainObject.getVersion();
}
@Override
public boolean isLive(MyData domainObject) {
return super.isLive(domainObject);
}
}
MyRepository is a Spring Repository with an injected EntityManager.
The only problem I still have is, that entityManager.persist(entity) returns
void.
And returning the created instance is a bad idea, since the primary key ID
is not yet generated.
*Do we really have to return the created object or may we return null*? The
only way out I see is to make another call to the repository and read the
newly generated object, when using JPA.
By the way, Repository must start and commit the DB Transaction.
Daniel
--
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.