Announcement Announcement Module
Collapse
No announcement yet.
"No property delete found" error when creating a custom repository implementation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • "No property delete found" error when creating a custom repository implementation

    Hi,

    I have this error when I try to define a custom repository implementation to all my repositories:

    2011-11-14 11:23:59.253:WARN::Nested in org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'nomenclatureRepository': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: No property delete found for type class be.leforem.nom.domain.Nomenclature:
    java.lang.IllegalArgumentException: No property delete found for type class be.leforem.nom.domain.Nomenclature

    Here is my repository factory bean:

    Code:
    package be.leforem.nom.dao.repository;
    
    import org.springframework.data.jpa.repository.JpaRepository;
    import org.springframework.data.jpa.repository.support.JpaRepositoryFactory;
    import org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean;
    import org.springframework.data.repository.core.RepositoryMetadata;
    import org.springframework.data.repository.core.support.RepositoryFactorySupport;
    
    import javax.persistence.EntityManager;
    
    public class RepositoryFactoryBean<T extends JpaRepository<?, ?>> extends JpaRepositoryFactoryBean {
    
        private EntityManager entityManager;
    
    
        public void setEntityManager(final EntityManager entityManager) {
            this.entityManager = entityManager;
            super.setEntityManager(entityManager);
        }
    
    
        public RepositoryFactorySupport getRepositoryFactory() {
            return new RepositoryFactory(entityManager);
        }
    
        private static class RepositoryFactory extends JpaRepositoryFactory {
    
            private EntityManager entityManager;
    
    
            private RepositoryFactory(final EntityManager entityManager) {
                super(entityManager);
                this.entityManager = entityManager;
            }
    
    
            @Override
            protected Object getTargetRepository(final RepositoryMetadata metadata) {
    
                return new CommonRepositoryImpl(getEntityInformation(metadata.getDomainClass()), entityManager);
            }
    
    
            @Override
            protected Class<?> getRepositoryBaseClass(final RepositoryMetadata metadata) {
    
                return CommonRepository.class;
            }
        }
    }
    Here is my custom interface:

    Code:
    package be.leforem.nom.dao.repository;
    
    import org.springframework.data.jpa.repository.JpaRepository;
    import org.springframework.data.repository.NoRepositoryBean;
    
    import java.io.Serializable;
    
    @NoRepositoryBean
    public interface CommonRepository<T,ID extends Serializable> extends JpaRepository<T, ID> {
    
        void deleteAndFlush(T entity);
    }
    Here is my custom repository implementation:

    Code:
    package be.leforem.nom.dao.repository;
    
    import org.springframework.data.jpa.repository.support.JpaEntityInformation;
    import org.springframework.data.jpa.repository.support.SimpleJpaRepository;
    import org.springframework.data.repository.NoRepositoryBean;
    
    import java.io.Serializable;
    import javax.persistence.EntityManager;
    
    @NoRepositoryBean
    public class CommonRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRepository<T, ID> implements CommonRepository<T, ID> {
    
        private final EntityManager entityManager;
    
    
        /**
         * Creates a new {@link SimpleJpaRepository} to manage objects of the given {@link JpaEntityInformation}.
         *
         * @param entityInformation
         * @param entityManager
         */
        public CommonRepositoryImpl(final JpaEntityInformation<T, ?> entityInformation, final EntityManager entityManager) {
            super(entityInformation, entityManager);
            this.entityManager = entityManager;
        }
    
    
        /**
         * Creates a new {@link SimpleJpaRepository} to manage objects of the given domain type.
         *
         * @param domainClass
         * @param em
         */
        public CommonRepositoryImpl(final Class<T> domainClass, final EntityManager em) {
            super(domainClass, em);
            entityManager = em;
        }
    
    
        @Override
        public void deleteAndFlush(final T entity) {
    
            delete(entity);
            flush();
        }
    }
    And of course, I referenced the factory class to the jpa:repositories bean:

    Code:
        <jpa:repositories base-package="be.leforem.nom.dao.repository"
                          factory-class="be.leforem.nom.dao.repository.RepositoryFactoryBean"
                          transaction-manager-ref="nom.transactionManager"
                          entity-manager-factory-ref="nom.entityManager"/>
    As I have to extends SimpleJpaRepository, I guess I have create the matching constructors.

    What's wrong with it ? Somebody can help me ?

    Thanks ! :o)
    Last edited by kernixski; Nov 20th, 2011, 06:15 AM.

  • #2
    It seems spring-data tries to generate a code on the base of the deleteAndFlush method. Then it expects the property delete exists on my persistable object. It's not the behavior that I expected... Maybe I'm doing something wrong. I tried to do the same with a custom repository (not a global one) and the error is the same. Do I have to annotate the method to tell to spring-data I don't want him to generate code for this method ?

    Comment


    • #3
      I didn't get the sample entirely (would you mind reformatting your original post using code tags?) but here's a minor glitch that might be responsible for the effect you see. getRepositoryBaseClass() expects the actual implementation class to be returned to inspect methods.

      Comment


      • #4
        Originally posted by Oliver Gierke View Post
        I didn't get the sample entirely (would you mind reformatting your original post using code tags?) but here's a minor glitch that might be responsible for the effect you see. getRepositoryBaseClass() expects the actual implementation class to be returned to inspect methods.
        Hi Oliver,

        I updated my post: the code is now formated.

        BTW, getRepositryBaseClass() returns my custom repository base class.

        Do you have an idea of the problem ? I have the same problem when I define a custom repository (not a global one).

        Comment


        • #5
          Well, no, it doesn't . You return CommonRepository which is the interface, not the implementation class CommonRepositoryImpl. You might wanna have a look at the test cases [0] that implement a custom repository factory and try to find out how your scenario differs from yours.

          [0] https://github.com/SpringSource/spri...ository/custom

          Comment


          • #6
            I missed this point. Thank you. :o)

            I will try my code with this change.

            Comment

            Working...
            X