10

是否可以像Vaadin一样使用org.springframework.data.jpa.repository.JpaRepository存储库?JPAContainer

我们正在使用 Spring 3.2 从头开始​​设置一个新的 Vaadin 7 项目。

Spring 集成是通过Spring Vaadin Integration Addon完成的。

4

3 回答 3

1

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.

JPAContainer issues and different approach

MVP pattern and POJO binding with Hibernate

于 2013-08-19T06:41:54.493 回答
1
    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);

        }
    }
于 2016-03-18T06:08:42.433 回答
0

Spring Data 不兼容 JPAContainer 的架构。一般来说,我建议根本不要使用 JPAContainer,而只是从 Spring Data 存储库中获取实体并将它们传递给 Vaadin 组件。例子:

grid.setContainerDataSource(new BeanItemContainer(Person.class, repo.findAll());

在 Vaadin 8 发布之前,我还建议使用 Viritin(我是作者,并且十年来一直在维护和开发 Vaadin),它可以为您提供更好的打字、更简单的 API 和更好的性能。有关完整堆栈示例应用程序,请参阅此 Spring Data CRUD 示例

于 2016-11-14T15:21:16.937 回答