Home

Awesome

JOPA-Spring-transaction

Integration of JOPA transactions into the Spring declarative transactions - the @Transactional annotation.

Notes

Usage

Usage of the library is fairly simple. It is only necessary to instantiate the JopaTransactionManager and DelegatingEntityManager Spring beans.

Do not forget to EnableTransactionManagement.

Assuming there is an EntityManagerFactory Spring bean, Java-based configuration of the aforementioned beans looks for example as follows:

@Configuration
@EnableTransactionManagement
@Import(PersistenceFactory.class)
public class PersistenceConfig {

    @Bean
    public DelegatingEntityManager entityManager() {
        return new DelegatingEntityManager();
    }

    @Bean(name = "txManager")
    public PlatformTransactionManager transactionManager(EntityManagerFactory emf, 
                                                         DelegatingEntityManager emProxy) {
        return new JopaTransactionManager(emf, emProxy);
    }
}

EntityManager is then injected into beans using Autowired or Inject (PersistenceContext is currently not supported, as it is closely tied to JPA):

@Autowired
private EntityManager em;

The tests contain a complete setup. For a fully operational example, see JOPA Example 04 - JOPA + Spring and the JSON-LD demo.

A full-fledged information system using JOPA and declarative Spring transactions is TermIt.

Getting the Library

The library is now available in Maven central, so getting it is just a matter of adding a Maven dependency:

<dependency>
    <groupId>com.github.ledsoft</groupId>
    <artifactId>jopa-spring-transaction</artifactId>
</dependency>

JOPA

See https://github.com/kbss-cvut/jopa.

License

MIT