Re: JPA self directed error

Blessed Sakweson <[email protected]> Thu, 30 Nov 2017 11:41:55 -0500
Newsgroups gmane.org.user-groups.ajug.members
Message-ID <[email protected]>
> This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

--===============6372362461685166818==
Content-type: multipart/alternative;
	boundary="B_3594886916_1591128029"

> This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

--B_3594886916_1591128029
Content-type: text/plain;
	charset="UTF-8"
Content-transfer-encoding: 7bit

Sometimes faster Jackson mapper runs into an endless loop when marshalling references. Take a look at your toString() method, if you included the reference in it, remove it and try again. Hopefully that helps.

 

From: ajug-members <[email protected]> on behalf of Mike Barnes <mike.barnes-f9aWwpgOZj5Wk0Htik3J/[email protected]>
Reply-To: <[email protected]>
Date: Thursday, November 30, 2017 at 11:38 AM
To: "[email protected]" <[email protected]>
Subject: [ajug-members] JPA self directed error

 

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 = FetchType.LAZY)

@JoinColumn(name="createdById")       

Private User createdBy;

@OneToOne(fetch = FetchType.LAZY)

@JoinColumn(name="modifiedById")    

Private User modifiedBy;

}

 

 

What am I doing incorrectly.

 

 

Thanks for all of you help in advance.

 

Mike Barnes

_______________________________________________ ajug-members mailing list [email protected] Manage your subscription and unsubscribe http://lists.ajug.org/mailman/listinfo/ajug-members


--B_3594886916_1591128029
Content-type: text/html;
	charset="UTF-8"
Content-transfer-encoding: quoted-printable

<html xmlns:o=3D"urn:schemas-microsoft-com:office:office" xmlns:w=3D"urn:schema=
s-microsoft-com:office:word" xmlns:m=3D"http://schemas.microsoft.com/office/20=
04/12/omml" xmlns=3D"http://www.w3.org/TR/REC-html40"><head><meta name=3DTitle c=
ontent=3D""><meta name=3DKeywords content=3D""><meta http-equiv=3DContent-Type conte=
nt=3D"text/html; charset=3Dutf-8"><meta name=3DGenerator content=3D"Microsoft Word 1=
5 (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;}
span.EmailStyle17
	{mso-style-type:personal-reply;
	font-family:"Calibri",sans-serif;
	color:windowtext;}
span.msoIns
	{mso-style-type:export-only;
	mso-style-name:"";
	text-decoration:underline;
	color:teal;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-size:10.0pt;}
@page WordSection1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
	{page:WordSection1;}
--></style></head><body bgcolor=3Dwhite lang=3DEN-US link=3Dblue vlink=3D"#954F72">=
<div class=3DWordSection1><p class=3DMsoNormal>Sometimes faster Jackson mapper r=
uns into an endless loop when marshalling references. Take a look at your to=
String() method, if you included the reference in it, remove it and try agai=
n. Hopefully that helps.<o:p></o:p></p><p class=3DMsoNormal><o:p>&nbsp;</o:p><=
/p><div style=3D'border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in =
0in 0in'><p class=3DMsoNormal><b><span style=3D'font-size:12.0pt;color:black'>Fr=
om: </span></b><span style=3D'font-size:12.0pt;color:black'>ajug-members &lt;a=
[email protected]&gt; on behalf of Mike Barnes &lt;mike.bar=
nes-f9aWwpgOZj5Wk0Htik3J/[email protected]&gt;<br><b>Reply-To: </b>&lt;[email protected]&gt;=
<br><b>Date: </b>Thursday, November 30, 2017 at 11:38 AM<br><b>To: </b>&quot=
;[email protected]&quot; &lt;[email protected]&gt;<br><b=
>Subject: </b>[ajug-members] JPA self directed error<o:p></o:p></span></p></=
div><div><p class=3DMsoNormal><o:p>&nbsp;</o:p></p></div><p class=3DMsoNormal>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:<o:p><=
/o:p></p><p class=3DMsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Direct self-reference leading to =
cycle; nested exception is com.fasterxml.jackson.databind.JsonMappingExcepti=
on<o:p></o:p></p><p class=3DMsoNormal>&nbsp;<o:p></o:p></p><p class=3DMsoNormal>=
DB table:<o:p></o:p></p><p class=3DMsoNormal>&nbsp;<o:p></o:p></p><p class=3DMso=
Normal style=3D'margin-left:.5in'>User {<o:p></o:p></p><p class=3DMsoNormal styl=
e=3D'margin-left:1.0in'>Long id,<o:p></o:p></p><p class=3DMsoNormal style=3D'margi=
n-left:1.0in'>Long CreatedById<o:p></o:p></p><p class=3DMsoNormal style=3D'margi=
n-left:1.0in'>Long ModifiedById<o:p></o:p></p><p class=3DMsoNormal style=3D'marg=
in-left:.5in'>}<o:p></o:p></p><p class=3DMsoNormal>&nbsp;<o:p></o:p></p><p cla=
ss=3DMsoNormal>JPA Class<o:p></o:p></p><p class=3DMsoNormal>&nbsp;<o:p></o:p></p=
><p class=3DMsoNormal style=3D'margin-left:.5in'>Public class User<o:p></o:p></p=
><p class=3DMsoNormal style=3D'margin-left:.5in'>{<o:p></o:p></p><p class=3DMsoNor=
mal style=3D'margin-left:1.0in'>Private long id;<o:p></o:p></p><p class=3DMsoNor=
mal style=3D'margin-left:1.0in'>@OneToOne(fetch =3D FetchType.LAZY)<o:p></o:p></=
p><p class=3DMsoNormal style=3D'margin-left:1.0in'>@JoinColumn(name=3D&quot;create=
dById&quot;)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <o:p></o:p></p><p class=3DMso=
Normal style=3D'margin-left:1.0in'>Private User createdBy;<o:p></o:p></p><p cl=
ass=3DMsoNormal style=3D'margin-left:1.0in'>@OneToOne(fetch =3D FetchType.LAZY)<o:=
p></o:p></p><p class=3DMsoNormal style=3D'margin-left:1.0in'>@JoinColumn(name=3D&q=
uot;modifiedById&quot;)&nbsp;&nbsp;&nbsp; <o:p></o:p></p><p class=3DMsoNormal =
style=3D'margin-left:1.0in'>Private User modifiedBy;<o:p></o:p></p><p class=3DMs=
oNormal style=3D'margin-left:.5in'>}<o:p></o:p></p><p class=3DMsoNormal>&nbsp;<o=
:p></o:p></p><p class=3DMsoNormal>&nbsp;<o:p></o:p></p><p class=3DMsoNormal>What=
 am I doing incorrectly.<o:p></o:p></p><p class=3DMsoNormal>&nbsp;<o:p></o:p><=
/p><p class=3DMsoNormal>&nbsp;<o:p></o:p></p><p class=3DMsoNormal>Thanks for all=
 of you help in advance.<o:p></o:p></p><p class=3DMsoNormal>&nbsp;<o:p></o:p><=
/p><p class=3DMsoNormal>Mike Barnes<o:p></o:p></p><p class=3DMsoNormal>_________=
______________________________________ ajug-members mailing list ajug-member=
[email protected] Manage your subscription and unsubscribe http://lists.ajug.=
org/mailman/listinfo/ajug-members<o:p></o:p></p></div></body></html>

--B_3594886916_1591128029--



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

X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KYWp1Zy1tZW1i
ZXJzIG1haWxpbmcgbGlzdAphanVnLW1lbWJlcnNAbGlzdHMuYWp1Zy5vcmcKTWFuYWdlIHlvdXIg
c3Vic2NyaXB0aW9uIGFuZCB1bnN1YnNjcmliZSBodHRwOi8vbGlzdHMuYWp1Zy5vcmcvbWFpbG1h
bi9saXN0aW5mby9hanVnLW1lbWJlcnM=

--===============6372362461685166818==--