1

is it possible use JPA in spring security ACL, I can see only jdbc implementation. here is my JPA setup in beans:

<beans:bean id="producerService" class="cz.services.RepositoryProducerService" />
<jpa:repositories base-package="cz.repository" />

<beans:bean id="myEmf"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <beans:property name="dataSource" ref="dataSource" />
    <beans:property name="packagesToScan" value="cz.models" />
    <beans:property name="jpaVendorAdapter">
        <beans:bean
            class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
    </beans:property>
    <beans:property name="jpaProperties">
        <beans:props>

            <beans:prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect
            </beans:prop>
            <beans:prop key="hibernate.show_sql">true</beans:prop>
        </beans:props>
    </beans:property>
</beans:bean>

<beans:bean id="transactionManager"
    class="org.springframework.orm.jpa.JpaTransactionManager">
    <beans:property name="entityManagerFactory" ref="myEmf" />
</beans:bean>

<beans:bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <beans:property name="url"
        value="jdbc:mysql://localhost:3306/mydb?zeroDateTimeBehavior=convertToNull&amp;characterEncoding=UTF-8" />

    <beans:property name="username" value="root" />
    <!--<property name="password" value="test" /> -->
    <beans:property name="password" value="test1"></beans:property>
</beans:bean>

but I have a problem with Transaction manager, beacuse I use org.springframework.orm.jpa.JpaTransactionManager instead of:

org.springframework.jdbc.datasource.DataSourceTransactionManager.

Main problem is when I start create acl, in first try I have exception transaction must be running, is second try (in broswer back and try it again) is it okay.

Here is error from first try:

java.lang.IllegalArgumentException: Transaction must be running
    at org.springframework.util.Assert.isTrue(Assert.java:65)
    at org.springframework.security.acls.jdbc.JdbcMutableAclService.createOrRetrieveSidPrimaryKey(JdbcMutableAclService.java:218)
    at org.springframework.security.acls.jdbc.JdbcMutableAclService$1.setValues(JdbcMutableAclService.java:135)
    at org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:899)
    at org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:890)

can someone help me with this? Thanks

Daris
  • 331
  • 1
  • 10

1 Answers1

1

Problem solved! :)

I search that JPA transaction manager in spring

A snippet from Spring 3's JavaDoc:

This transaction manager also supports direct DataSource access within a transaction (i.e. plain JDBC code working with the same DataSource). This allows for mixing services which access JPA and services which use plain JDBC (without being aware of JPA)!

but problem was in my cglib - I have to use

<tx:annotation-driven transaction-manager="transactionManager" />

and remove @Transactional from interface JPA repository.

I found solution here too : What transaction manager should I use for JBDC template When using JPA ?

hope someone help it.

Community
  • 1
  • 1
Daris
  • 331
  • 1
  • 10