Announcement Announcement Module
Collapse
No announcement yet.
Trouble adding custom query to a single repository Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Trouble adding custom query to a single repository

    This is kind of a newbie question and I'm sorry if I'm missing something really obvious. I have read the docs at http://static.springsource.org/sprin...tory-behaviour and I'm still stuck. I'm using Spring Data 1.1.0 and Hibernate 3.6.6.

    Basically what I want to do is add one custom query to a repository extending JpaRepository. This will only need to be applied to one repository, so creating a custom query interface, implementing it, and then adding it to the interfaces extended by the main repository seemed like the way to go. The problem here is that Spring seems to be forcing me to map my method to a property of the entity object, even though I have added the @NoRepositoryBean annotation.

    Here is my main repository interface:

    Code:
    @Repository("VideoItemRepository")
    public interface VideoItemRepository extends JpaRepository<VideoItem, Long>, 
    	VideoRepositoryCustom {
    
    }
    Here is the custom repository interface:

    Code:
    @NoRepositoryBean
    public interface VideoRepositoryCustom {
    	public void someCustomMethod(VideoItem video);
    }
    And the implementation...


    Code:
    public class VideoRepositoryCustomImpl implements VideoRepositoryCustom {
    
    	@Override
    	public void someCustomMethod(VideoItem video) {
    		System.out.println("DEBUG: someday this will do amazing things. For now, here is our custom method with the video " + video.toString());
    		
    	}
    
    }

    When I run this, I get a "Could not create query metamodel" exception saying that it is unable to find the property "some." Clearly, it is trying to map my VideoItem class to the custom method. Is there a way to prevent that mapping, or perhaps another way to go about this? My real goal here is to add one custom query method to the JpaRepository so that I can implement some logic that goes a bit beyond what I can do in the standard JPA. I realize that there are other options involving Querydsl and Predicates, but that really seems like overkill for a fairly simple problem. Surely there is a way to make this happen?

    Thanks,
    Alex

  • #2
    Attachment
    My English so bad、、、、、
    Attached Files

    Comment

    Working...
    X