Announcement Announcement Module
Collapse
No announcement yet.
Unable to add custom methods to Spring Data repository generated by Roo Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unable to add custom methods to Spring Data repository generated by Roo

    Using the script below, Roo generates repository/DAO layer containing Book.java (javabean), BookRepository.java (interface), and some .aj files (Non-editable).

    Code:
    ...
    entity jpa --class ~.Book --activeRecord false
    field date --fieldName rentalDate --type java.util.Date
    field number --fieldName isbn --type java.lang.Integer
    field string --fieldName title
    repository jpa --interface ~.BookRepository
    I package the DAO layer as .jar file and I use it as follow on another project (Without Spring Roo):
    Code:
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath*:META-INF/spring/applicationContext*.xml");
    
    BookRepository bookRepo = (BookRepository)springContext.getBean("BookRepository");
    bookRepo.saveAndFlush(entity);
    Now, I need to introduce custom methods to perform more complex data access but I want to keep access still coming from the same interface, eg.
    Code:
    bookRepo.doSomething(bookId)
    However, I do not know where to put the implementation of the method since there is no Java class where I can put the implementation (I only have Book.java and BookRepository.java), furthermore BookRepository.java demands me to specify @Query.

    If you have thought about this scenario when designing Spring Roo, please help.
    Thank you.
    Last edited by cix.yong; Feb 16th, 2013, 04:02 AM.

  • #2
    found the solution. Create:
    BookRepositoryCustom.java to contain doSomething(bookId)
    BookRepositoryImpl.java to contain impl of doSomething(bookId)

    Code:
    @RooJpaRepository(domainType = Book.class)
    public interface BookRepository extends BookRepositoryCustom {
    }

    Comment

    Working...
    X