Announcement Announcement Module
Collapse
No announcement yet.
Sub-Sub Interface of Repository Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sub-Sub Interface of Repository

    Hello Friends,

    I have a doubt concerning extending the Repository interface and it sub types (e.g. JpaRepository), that I could not made clear in the reference, forum and the issue tracker.

    I'm working with two OSGi bundles:
    In the first bundle I have one domain class and it's jpa repository interface (which extends the JpaRepository interface, and just add a findByAttribute method), which I'll call, just for clarification, DomainRepository.
    In the second one I have just one empty interface (i.e. sub-sub-interface of JpaRepository) that extends the DomainRepository, that I'll call DomainService and from which I want to export an osgi service.

    Now, the problem is, in runtime the bean for the DomainService cannot be created I not quite sure why. I get a IllegalArgumentException with the message:
    Code:
    You have custom methods in interface org.example.DomainService but not provided a custom implementation!
    thrown by RepositoryFactorySupport.validate()

    When I use the DomainRepository directly it works as expected. Because of some design choices we prefer the sub-sub-interface approach.

    So, given the scenario, my question is: There's a limitation in the RepositoryFactorySupport that do not allow sub-sub-interfaces for the bean creation?

    thanks in advance,
    Paulo

  • #2
    Actually there shouldn't be a limitation on the various ways you can use interfaces with the repository approach. Is there a chance you can show us the two interfaces that you've defined?

    Cheers,
    Ollie

    Comment


    • #3
      Originally posted by Oliver Gierke View Post
      Is there a chance you can show us the two interfaces that you've defined?
      Of course. So, in the first bundle I have this interface.
      Code:
      public interface AmbulanceVehicleRepository extends JpaRepository<AmbulanceVehicle, Long> {
      	
      	/**
      	 * @param String label
      	 * @return AmbulanceVehicle the labelled ambulance in storage
      	 */
      	AmbulanceVehicle findByLabel(String label);
      }
      AmbulanceVehicle is my jpa2 domain class, with a Long id field.

      Then, in the second bundle, I'm just extending my AmbulanceVehicleRepository interface. So:
      Code:
      public interface SpringDataVehicleAdminRepository extends AmbulanceVehicleRepository {
      
      }
      And then I have the error. I (trying to) create the bean using spring-data "repositories" element in the context and autowiring it in the code for later usage.


      regards,
      Paulo
      Last edited by paulo.mach; May 3rd, 2011, 11:18 AM.

      Comment


      • #4
        Same problem here

        We are right now evaluating the spring-data and we have the same problem as with "Sub-Sub". Is this something that will be solved in the near future?

        Comment


        • #5
          Solution for the &quot;sub-sub&quot; interface problem

          A solution for that was add in the interface a override of the method declared in the first interface, so:

          Code:
          public interface SpringDataVehicleAdminRepository extends AmbulanceVehicleRepository {        
                   @Override
                   AmbulanceVehicle findByLabel(String label);
          }
          Now works fine.

          Comment


          • #6
            I am just about to release Spring Data JPA RC1 that uses a Spring Data Commons build that should have this one fixed. See [0], especially the test considersIntermediateMethodsAsFinderMethods() for details.

            [0] https://github.com/SpringSource/spri...e9c8e52201d10f

            Comment


            • #7
              Great news Oliver. Thanks for the reply.

              Comment


              • #8
                I've tested with the fresh 1.0.0.RC1 and everything went well using the first approach of the "sub-sub" interface.

                Comment


                • #9
                  Great news, thanks for the feedback!

                  Comment

                  Working...
                  X