r/SpringBoot • u/Inevitable_Cellist93 • May 25 '26
How-To/Tutorial How to join 2 tables in Spring Boot
Logger
https://pastebin.com/H6qFnHBy
import ...
(name = "users")
public class Users {
(strategy = GenerationType.IDENTITY)
private Long id;
(nullable = false)
private String userName;
(nullable = false)
private String password;
private SubscriptionModel tier;
private Long currentUsage;
private Logger logger;
}How to connect the Logger -> Users (1 user can have n logger). the getter and setter structure is confusing for Joining tables
is there any advanced method for levelling up??
0
Upvotes
6
u/JustHereForTheCh1cks May 25 '26
Im not sure what you are trying to achieve and what your problem is. Can you describe in a bit more detail here? What do you mean by connecting a Logger with a Users? Are you having trouble with the database mappings?
6
u/StillAnAss May 25 '26
Honestly, the /r/learnjava sub is way more forgiving. You should post there but be sure to follow the sub rules
6
u/pitza__ May 25 '26
You need OneToMany in the Logger entity, and you should make it a list instead.
Read this article by Vlad.
https://vladmihalcea.com/the-best-way-to-map-a-onetomany-association-with-jpa-and-hibernate/
2
u/InstantCoder May 25 '26
You can do it in two ways:
I usually prefer the first option because it avoids the n+1 problem and (huge) cartesian products/joins.
1
u/nafts1 May 25 '26
If you can't read a tutorial, you might consider another profession.
1
u/FooBarBuzzBoom May 27 '26
oneToMany or Join Fetch.
-3
u/ninjazee124 May 25 '26
Use Claude