Spring 个实体未保存到数据库

Spring Entities Not Saved To Database

我们已经建立了这样的 Spring 框架:

@Eager
public interface CatalogElementRepository extends PagingAndSortingRepository<CatalogElementEntity, Long> {

}

@Service
public class CatalogImpl implements CatalogManager {

    @Inject
    CatalogElementRepository catalogElementRepository;

    @Override
    public CatalogElement createCatalogElement(CatalogElementEntity catalogElement) {
    return this.catalogElementRepository.save(catalogElement);
    }
}

@Stateless
@Remote(CatalogManager.class)
public class CatalogManagerBean implements CatalogManager {

    @Inject
    CatalogManager delegate;

    @Override
    public CatalogElement createCatalogElement(CatalogElementEntity catalogElement) {
        return this.delegate.createCatalogElement(catalogElement);
    }
}

因此,每当有人在远程接口 createCatalogElement 上调用该方法时,我会假设该实体已存储在数据库中。它不是(奇怪的是,findOne 仍然是 returns 同一个实体,但无法通过 findByProperty 找到它)。

Other 说要加@Transactional,所以我在方法上加了@javax.transaction.Transactionalorg.springframework.transaction.annotation.Transactional,为了保险起见,加了类,没什么成功了。

可能是什么问题?

我没有看到 Spring 框架的任何配置文件,但它是一个遗留项目,因此它们可能隐藏得很好。

出于某种原因,使用此 class 作为 EntityManager 的制作人帮助:

public class SpringConfig {

@PersistenceUnit
EntityManagerFactory emf;

@PersistenceContext
EntityManager em;

@Produces
@ApplicationScoped
public EntityManagerFactory createEntityManagerFactory() {
    return this.emf;
}

@Produces
public EntityManager createEntityManager() {
    return this.em;
}

public void close(@Disposes EntityManagerFactory entityManagerFactory) {
    entityManagerFactory.close();
}

public void close(@Disposes EntityManager entityManager) {
    entityManager.close();
}
}