Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.1 RC1
    • Component/s: None
    • Labels:
      None

      Description

      An additional annotation which indicates that locking should be used.

      public interface ContactRepository extends JpaRepository<Contact, Long> {
        @Lock(LockModeType.PESSIMISTIC_WRITE)
        public Contact findById( Long id );
      }
      

      and

        @Query("select c from Contact c where c.username = ?")
        @Lock(LockModeType.READ)
        public List<Contact> findByName(String name);
      

      Also mentioned: http://redmine.synyx.org/boards/2/topics/257

        Activity

        Hide
        Raphael Vullriede added a comment -

        I'd like to have that feature, too. Currently it is not possible to use pessimistic locking without directly messing around with an EntityManager.

        Show
        Raphael Vullriede added a comment - I'd like to have that feature, too. Currently it is not possible to use pessimistic locking without directly messing around with an EntityManager.
        Hide
        Oliver Gierke added a comment -

        Repository query methods can now be equipped with a @Lock annotation that carries the LockModeType to be used when executing the query. Beyond that, CRUD methods can be redeclared to carry lock metadata as well.

        interface UserRepository extends Repository<User, Long> {
        
          // CRUD method redeclaration
          @Lock(LockModeType.READ)
          List<User> findAll();
        
          // Query method
          @Lock(LockModeType.READ)
          List<User> findByLastname(String lastname);
        }
        

        Thanks to Aleksander Blomskøld for providing the query execution side of the implementation!

        Show
        Oliver Gierke added a comment - Repository query methods can now be equipped with a @Lock annotation that carries the LockModeType to be used when executing the query. Beyond that, CRUD methods can be redeclared to carry lock metadata as well. interface UserRepository extends Repository<User, Long > { // CRUD method redeclaration @Lock(LockModeType.READ) List<User> findAll(); // Query method @Lock(LockModeType.READ) List<User> findByLastname( String lastname); } Thanks to Aleksander Blomskøld for providing the query execution side of the implementation!
        Hide
        Raphael Vullriede added a comment -

        Thanks for the quick implementation. I'll give it a try
        btw. since there seems to be no JIRA <-> GIT integration, can you please provide a link to the changeset?

        Show
        Raphael Vullriede added a comment - Thanks for the quick implementation. I'll give it a try btw. since there seems to be no JIRA <-> GIT integration, can you please provide a link to the changeset?
        Hide
        Oliver Gierke added a comment -

        Actually the source tab lists the commits but here's the direct link for your convenience .

        Show
        Oliver Gierke added a comment - Actually the source tab lists the commits but here's the direct link for your convenience .

          People

          • Assignee:
            Oliver Gierke
            Reporter:
            Andreas Buechele
          • Votes:
            2 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 0d
              0d
              Remaining:
              Remaining Estimate - 0d
              0d
              Logged:
              Time Spent - 2.5h
              2.5h