Results 1 to 9 of 9

Thread: Sub-Sub Interface of Repository

Hybrid View

  1. #1
    Join Date
    Apr 2011
    Location
    Aachen, Germany
    Posts
    16

    Default 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. #2
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    483

    Default

    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

  3. #3
    Join Date
    Apr 2011
    Location
    Aachen, Germany
    Posts
    16

    Default

    Quote 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 at 10:18 AM.

  4. #4
    Join Date
    May 2011
    Posts
    4

    Default 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?

  5. #5
    Join Date
    Apr 2011
    Location
    Aachen, Germany
    Posts
    16

    Default Solution for the "sub-sub" 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.

  6. #6
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    483

    Default

    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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •