Trying to run Spring-Boot JPA on MySQL and literally followed this tutorial here : https://spring.io/guides/gs/accessing-data-mysql/ All went well as expected.
However, moment I brought in a new Entity viz. Address of the User and established 1-to-1 unidirectional mapping, the Application starts to throw StackOverFlow error - even though the mapping is very basic that I have used without issues on App Servers (e.g GlassFish/Payara 5) several times.
Below is the mapping :
In User Entity
@OneToOne(mappedBy = "user", optional = false, cascade = CascadeType.ALL) private Address address; ..the other side of the relationship i.e. in Address :
@OneToOne(fetch = FetchType.LAZY) @JoinColumn(name="USER_ID") private User user; Expected : A single line : {"id":1,"name":"First","email":"[email protected]","address":{"id":2,"line1":"Line1","postcode":"PST CD","city":"City","state":"State","country":"IN"
Actual : The above line being printed on console countless times this there is a StackOverflow Error.