JPA self directed error

Mike Barnes <mike.barnes-f9aWwpgOZj5Wk0Htik3J/[email protected]> Thu, 30 Nov 2017 08:37:51 -0800
Newsgroups gmane.org.user-groups.ajug.members
Message-ID <[email protected]>
--===============4257408840284668895==
Content-Type: multipart/alternative;
	boundary="_38724D98-498F-41A7-B946-32EA052BBB8A_"

--_38724D98-498F-41A7-B946-32EA052BBB8A_
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="utf-8"

I have a user class that has a modifiedBy and createdBy columns that point =
to the user class. When I try and run the code I get the following error:
	Direct self-reference leading to cycle; nested exception is com.fasterxml.=
jackson.databind.JsonMappingException

DB table:

User {
Long id,
Long CreatedById
Long ModifiedById
}

JPA Class

Public class User
{
Private long id;
@OneToOne(fetch =3D FetchType.LAZY)
@JoinColumn(name=3D"createdById")=09
Private User createdBy;
@OneToOne(fetch =3D FetchType.LAZY)
@JoinColumn(name=3D"modifiedById")=09
Private User modifiedBy;
}


What am I doing incorrectly.


Thanks for all of you help in advance.

Mike Barnes

--_38724D98-498F-41A7-B946-32EA052BBB8A_
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset="utf-8"

<html xmlns:o=3D"urn:schemas-microsoft-com:office:office" xmlns:w=3D"urn:sc=
hemas-microsoft-com:office:word" xmlns:m=3D"http://schemas.microsoft.com/of=
fice/2004/12/omml" xmlns=3D"http://www.w3.org/TR/REC-html40"><head><meta ht=
tp-equiv=3DContent-Type content=3D"text/html; charset=3Dutf-8"><meta name=
=3DGenerator content=3D"Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:#954F72;
	text-decoration:underline;}
.MsoChpDefault
	{mso-style-type:export-only;}
@page WordSection1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
	{page:WordSection1;}
--></style></head><body lang=3DEN-US link=3Dblue vlink=3D"#954F72"><div cla=
ss=3DWordSection1><p class=3DMsoNormal>I have a user class that has a modif=
iedBy and createdBy columns that point to the user class. When I try and ru=
n the code I get the following error:</p><p class=3DMsoNormal>=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0 Direct self-reference leading to cycle; nested exception is com.fasterx=
ml.jackson.databind.JsonMappingException</p><p class=3DMsoNormal><o:p>&nbsp=
;</o:p></p><p class=3DMsoNormal>DB table:</p><p class=3DMsoNormal><o:p>&nbs=
p;</o:p></p><p class=3DMsoNormal style=3D'margin-left:.5in'>User {</p><p cl=
ass=3DMsoNormal style=3D'margin-left:1.0in'>Long id,</p><p class=3DMsoNorma=
l style=3D'margin-left:1.0in'>Long CreatedById</p><p class=3DMsoNormal styl=
e=3D'margin-left:1.0in'>Long ModifiedById</p><p class=3DMsoNormal style=3D'=
margin-left:.5in'>}</p><p class=3DMsoNormal><o:p>&nbsp;</o:p></p><p class=
=3DMsoNormal>JPA Class</p><p class=3DMsoNormal><o:p>&nbsp;</o:p></p><p clas=
s=3DMsoNormal style=3D'margin-left:.5in'>Public class User</p><p class=3DMs=
oNormal style=3D'margin-left:.5in'>{</p><p class=3DMsoNormal style=3D'margi=
n-left:1.0in'>Private long id;</p><p class=3DMsoNormal style=3D'margin-left=
:1.0in'>@OneToOne(fetch =3D FetchType.LAZY)</p><p class=3DMsoNormal style=
=3D'margin-left:1.0in'>@JoinColumn(name=3D&quot;createdById&quot;)=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0 </p><p class=3DMsoNormal style=3D'margin-left:1=
.0in'>Private User createdBy;</p><p class=3DMsoNormal style=3D'margin-left:=
1.0in'>@OneToOne(fetch =3D FetchType.LAZY)<o:p></o:p></p><p class=3DMsoNorm=
al style=3D'margin-left:1.0in'>@JoinColumn(name=3D&quot;modifiedById&quot;)=
=C2=A0=C2=A0=C2=A0 <o:p></o:p></p><p class=3DMsoNormal style=3D'margin-left=
:1.0in'>Private User modifiedBy;</p><p class=3DMsoNormal style=3D'margin-le=
ft:.5in'>}</p><p class=3DMsoNormal><o:p>&nbsp;</o:p></p><p class=3DMsoNorma=
l><o:p>&nbsp;</o:p></p><p class=3DMsoNormal>What am I doing incorrectly.<o:=
p></o:p></p><p class=3DMsoNormal><o:p>&nbsp;</o:p></p><p class=3DMsoNormal>=
<o:p>&nbsp;</o:p></p><p class=3DMsoNormal>Thanks for all of you help in adv=
ance.<o:p></o:p></p><p class=3DMsoNormal><o:p>&nbsp;</o:p></p><p class=3DMs=
oNormal>Mike Barnes<o:p></o:p></p></div></body></html>=

--_38724D98-498F-41A7-B946-32EA052BBB8A_--


--===============4257408840284668895==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: inline

X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KYWp1Zy1tZW1i
ZXJzIG1haWxpbmcgbGlzdAphanVnLW1lbWJlcnNAbGlzdHMuYWp1Zy5vcmcKTWFuYWdlIHlvdXIg
c3Vic2NyaXB0aW9uIGFuZCB1bnN1YnNjcmliZSBodHRwOi8vbGlzdHMuYWp1Zy5vcmcvbWFpbG1h
bi9saXN0aW5mby9hanVnLW1lbWJlcnM=

--===============4257408840284668895==--