Introduction to Spring Data JPA - Creating Queries Part 1

preview_player
Показать описание

In this tutorial we are going to look at query creation on Spring Data JPA. We know that when we extend the CRUD Repository interface we get some methods out of the box such findAll, save and delete. What happens when you want to start creating custom queries though? In this tutorial we will look at that exact scenario.

Source Code

Spring Data JPA - Reference Documentation

Please Subscribe to this channel and leave a comment below.

Рекомендации по теме
Комментарии
Автор

Done thanks
1:10 Post entity definition. Each post has an Author. Author field annotated with @ManyToOne (many posts to one author)


11:40 selecting posts by author name does a left outer join (posts table with author table) to select based on author name column


When getting posts (through post repository) by Author *name*, the name is not in the Post table, so hibernate does a join between the post table and author table on the author_id to then have columns look like this for example:
Column1) Post_id, Column2) Post_name, Column3) Post_content, *Column4)* Author_name
Then selecting based on where clause.
The join is necessary here because Post table doesn't have Author name (only has author id)
If we were doing find posts by author id, we wouldn't need a join and can just select from posts where author_id = ...

mostinho
Автор

Thanks a lot for the tutorial. Much appreciated!

nsfnd
Автор

Hello Dan, do you still have that discount on your course? By the way Great Example

kapoeiradobrasil
Автор

I have a Q: @RestController vs @Controller is the advantage of the @RestController is : if we use AJAX to update the web content without refreshing the page? but if we use the @Controller doesnt update the web content when using AJAX.?? Thanks for explaining

aobaidi
Автор

Caused by: customer is not mapped
at
at
at ~[hibernate-core-5.0.9.F


i got an error when i try to customize query .

public interface PostRepository extends CrudRepository<Customer, Long>{
@Query("select c from customer c where c.fistname = ?1")
List<Customer> findByFirst(String firstname);
}


please help!

allcollection
Автор

it's great tutorial .i have a request . Can you show how to configure database ?

allcollection
Автор

thanks for the tut, but i kept thinking someone was stomping upstairs, scared me, not sure if thats your arm on desk or what.

antytrend
Автор

I like your video a lot. Thx for share :)

ytSpoiler
Автор

So can u use this instead of classic Hibernate ? I mean for complex web apps.

Smolandgor
Автор

Where are the methods findAll(), save() etc implemented?

jonsnow