Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Spring
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Ron McLeod
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Rob Spoor
Junilu Lacar
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Piet Souris
Carey Brown
Bartenders:
Forum:
Spring
How to create counter in Spring
Molayo Decker
Ranch Hand
Posts: 48
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
I am trying to create a counter using the JPQL in spring so that when the user save a form it counts by one.
This what i did but it's not working.
@Repository public interface ExamsDao extends CrudRepository<Exams,Long>{ @Query("select e from Exams e join e.user u where u.id= ?#{principal.id}") List<Exams> findAll(); @Query("update Exams SET counter = counter + 1") Exams counter(); }
@Service public class ExamServiceImpl implements ExamService { @Autowired private ExamsDao examsDao; @Override public Iterable<Exams> findAll() { return examsDao.findAll(); } @Override public Exams findOne(Long id) { return examsDao.findOne(id); } @Override public void toggleComplete(Long id) { Exams exams = examsDao.findOne(id); exams.setComplete(!exams.isComplete()); examsDao.save(exams); } @Override public void save(Exams exams) { examsDao.save(exams); } @Override public Exams counter() { return examsDao.counter(); } }
Ankit Garg
Sheriff
Posts: 9697
43
I like...
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi Molayo, can you
add more details
to your question. Which part doesn't work, does the spring context comes up and the save doesn't work?
SCJP 6 | SCWCD 5 |
Javaranch SCJP FAQ
|
SCWCD Links
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Hibernate /JPA and Spring Data statistics join 2 tables. Result from talbe 1 daily values
JPA Optimistic Locking Test
Delete Bidirectional many to one Entities
Problem with @autowiring beans in Spring/Maven Project
Spring Data: fetch join when using Specification and Pageable
More...