#EntityA with List<EntityB>. How to make it with database

1 messages · Page 1 of 1 (latest)

hallow anvil
#

I fried my brain while trying to understand this.

@Entity
public class Library {
  private Long id;
  private String address;
  private List<Book> books;
}

@Entity
public class Book {
  private Long id;
  private String name;
}

@Controller
public class LibraryController {
  public List<Book> findALlBooks() {
    libraryService.findAllBooks();
  }
}

Have no idea how to make it. + how db should look like

fading merlinBOT
#

<@&987246584574140416> please have a look, thanks.

thin crane
#

you might want to look into one to many relationships

#

like one-to-many and many-to-one

hallow anvil
thin crane
hallow anvil
tribal hedge
raven creek
#

What do you mean? As Squid said that's a one-to-many.

#

Or in this case a many-to-many dependant on how you define a visitor.

fading merlinBOT
#

@hallow anvil

Your question has been closed due to inactivity.

If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.

Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.

When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.

Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.

With enough info, someone knows the answer for sure 👍

tribal hedge
raven creek
#

What do you mean with how does it work?

#

And I'm a bit unclear what's unclear for you about one to many or many to one.

#

One book can be read by multiple people, A person can read multiple books. A person has a specific DNA pattern. Etc..

#

I recommend looking at Squid's link.

thin crane
raven creek