是否可以像Vaadin一样使用org.springframework.data.jpa.repository.JpaRepository
存储库?JPAContainer
我们正在使用 Spring 3.2 从头开始设置一个新的 Vaadin 7 项目。
Spring 集成是通过Spring Vaadin Integration Addon完成的。
是否可以像Vaadin一样使用org.springframework.data.jpa.repository.JpaRepository
存储库?JPAContainer
我们正在使用 Spring 3.2 从头开始设置一个新的 Vaadin 7 项目。
Spring 集成是通过Spring Vaadin Integration Addon完成的。
As far as you can get EntityProvider from JPARepository or somewhere else you can use JPAContainer like this:
EntityManager entityManager = getEntityManager(Campaign.class));
MutableLocalEntityProvider<Campaign.class)> provider;
provider = new CachingMutableLocalEntityProvider<Campaign.class)>(Campaign.class), entityManager);
provider.setTransactionsHandledByProvider(false);
JPAContainer<Campaign> container = new JPAContainer<Campaign>(Campaign.class); container.setEntityProvider(EntityProviderUtil.get().getEntityProvider(Campaign.class));
or jsut simple
EntityManager entityManager = getEntityManager(Campaign.class));
JPAContainer<Campaign> container = JPAContainerFactory.make(Campaign.class, entityManager)
Well, you should read following post and decide if you did not want to use you JPARepository as a model layer and wrap it into BeanItemContainer, cuz JPAContainer looks good but has some performance issues from my point of view.
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import com.vaadin.addon.jpacontainer.JPAContainer;
import com.vaadin.addon.jpacontainer.JPAContainerFactory;
@SpringComponent
public class SpringDataVaadinJPAContainer {
@PersistenceContext
private EntityManager entityManager;
public SpringDataVaadinJPAContainer() {
JPAContainer<Person> container = JPAContainerFactory.make(Person.class, entityManager);
}
}
Spring Data 不兼容 JPAContainer 的架构。一般来说,我建议根本不要使用 JPAContainer,而只是从 Spring Data 存储库中获取实体并将它们传递给 Vaadin 组件。例子:
grid.setContainerDataSource(new BeanItemContainer(Person.class, repo.findAll());
在 Vaadin 8 发布之前,我还建议使用 Viritin(我是作者,并且十年来一直在维护和开发 Vaadin),它可以为您提供更好的打字、更简单的 API 和更好的性能。有关完整堆栈示例应用程序,请参阅此 Spring Data CRUD 示例。