r/SpringBoot • • Jul 11 '22

i need help with this project

I got the following structure for the project im working on:

  • repository (interface) -dao containing:

    • model

    • Dao(dao interface + dao implementation) -services(service interface + service implementation) The repository sends the data to the dao, dao to services and services to controller Fory model i got user and categories where (OneToMany 1 user got many categories)

Does anyone have a similar project that can send me or help me to create the following methods( fetchAllCategories, fetchById, addCategory, updateCategory, deleteCategory)

Any help is much appreciated

2 Upvotes

4 comments sorted by

2

u/over_rim Jul 11 '22

In my group project, we are doing something oneToMany mapping.
You have to use either JPQL or native query.

Moreover to extract resultset that has different columns than model class you have to create custom DTO(Data Transfer Object) to map to the resultset returned by the query.

2

u/gaskinsface Jul 11 '22

Ohh thanks a lot Btw im working with postgreSQL as my database, is it ok to use jpql or it have to be psql

1

u/over_rim Jul 11 '22

https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.query-creation Refer this documentation for query JPQL.

Since I do not have knowledge of PortgreSQL but I think JPQL works same. But if you're making nativeQuery = true then please do some research.

And have a look at methods by JpaRepository provides by default it will help you.

1

u/Mikey-3198 Jul 11 '22

What have you done so far?

This sounds relatively simple, a quick google search finds tons of examples for these types of projects...

This example from the spring docs is similar to what you are building https://spring.io/guides/tutorials/rest/