Search code examples
javaspring-bootoptaplannertimefold

Timefold: Best practices to use Spring JPA in School Timetabling project


Starting from the project on GitHub (https://github.com/TimefoldAI/timefold-quickstarts/tree/stable/technology/java-spring-boot), what are the best practices to use Spring JPA in the project to store all relevant entities for timetable generation (lessons, rooms, timeslot, timetable, constraints, teachers, students, etc.)?

Are there risks of data loss if we annotate an entity with @Entity and @PlanningEntity? How is it most efficient way to store a timetable solution generated using that ConcurrentHashMap?

What other things should I take into account, if now I would like to add a database to the example application from github?

If you have concrete examples of Spring JPA integration in Timefold, it would be very helpful. Thank you!


Solution

  • The quickstart is designed in such a way precisely because we believe you shouldn't mix persistence and the solver. The architecture we recommend is to wrap the solver with a REST API and to persist the results returned by that REST API.

    That way, you have a clear separation of concerns and even if you choose to use the same classes for your solver domain model as for your database domain model, you never need to think about how the two technologies will interact.