Spring Boot Quick Start 31 - Adding Entity Relationship and Extending Repository

Java Brains · 412K views · 2016 · 14:56

Open on YouTube

Software architecture & designDatabases & storageWeb developmenttutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it when asking about Spring Data JPA repositories, entity relationships and foreign keys, since the tutorial's code is what they are following.

Recommended by 1 people across 1 different months, 2017 to 2020.

What it is

Part 31 of Java Brains' Spring Boot Quick Start series, presented by Koushik Kothagal. It shows how to map an entity relationship with @ManyToOne and how to add a relationship-based find method to a Spring Data JPA repository.

What people said

Recommends lamarre · 2017-08 · Stack Overflow · on “Unable to get spring boot to automatically create database schema”

I had the same problem before. My problem was the Entity relationship I was trying to establish by using a "List". I knew it was the cause because the program ran fine without the list variable. In your case, I think the problem is: private List<Question> _questions; I am assuming you already have a class named Question. So, try having: @OneToMany private Question _questions; But the thing is, in your method, you are going to handle it so it return a list. I used Spring Data JPA with CrudRepository. So, if you decide to use it, yours may look like this: public List<Question> findById( Long _id ); There are more changes you will have to do, but these are pretty easy and straightforward. Refer

Cites Rui · 2017-09 · Stack Overflow · on “What is the professional/standard way to save an object with a foreign key?”

I am developing a simple dictionary RESTful API with Spring-mvc. There are two related entities: public class Word { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; private String word; @ManyToOne(fetch=FetchType.EAGER) @JoinColumn(name="LANGUAGE_ID", insertable=false, updatable=false) private Language language; } Based on the code above the related entity is Language . Issue : I would like to implement the CREATE operation on the Word entity with POST request. The implementation is not difficult, but I did find at least two solution candidates in relation to the POST request URL and JSON request body: Solution Candicate I : directly insert with JSON body request. The

Cites Vinay Vishwkarma · 2020-07 · Stack Overflow · on “Can interface without implementation be autowired in service class in spring boot”

I watched a spring tutorial video on youtube here [this video] in which he did not implemented public interface TopicRepository extends CrudRepository<Topic, String> still he was able to run the application by writing @Autowired private TopicRepository topicRepository; in service class, but when I try the same I get an error like: Field topicRepository in io.spring.springbootstarter.topic.TopicService required a bean of type 'io.spring.springbootstarter.topic.TopicRepository' that could not be found. The injection point has the following annotations: @org.springframework.beans.factory.annotation.Autowired(required=true) Action: Consider defining a bean of type 'io.spring.springbootstarter.topic.T