<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Update vs insert</TITLE>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.3314" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=465015110-11092008><FONT face=Arial
color=#0000ff size=2>What version of Drools are you using?</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=465015110-11092008><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=465015110-11092008><FONT face=Arial
color=#0000ff size=2>Pre-5 has "Shadow Facts" so you can't rely upon
pass-by-reference. I believe 5 has had Shadow Facts removed.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=465015110-11092008><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=465015110-11092008><FONT face=Arial
color=#0000ff size=2>Insert places a new object into WM whereas update refreshes
(the shadow) of an existing one.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=465015110-11092008><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=465015110-11092008><FONT face=Arial
color=#0000ff size=2>I would expect you to have to use update in your
example:-</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=465015110-11092008><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=465015110-11092008><FONT color=#0000ff><FONT
face="Courier New" size=2>rule "Add person to math class"</FONT><FONT
face="Courier New"><FONT size=2><FONT color=#000000> <BR></FONT><SPAN
lang=en-us><FONT color=#0000ff>
no-loop</FONT></SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><FONT
color=#000000> <BR></FONT><SPAN lang=en-us><FONT
color=#0000ff>
when</FONT></SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><FONT
color=#000000> <BR></FONT><SPAN lang=en-us><FONT
color=#0000ff>
person : Person(likesMath == true)</FONT></SPAN></FONT></FONT><FONT
face="Courier New"><FONT size=2><FONT color=#000000> <BR></FONT><SPAN
lang=en-us><FONT color=#0000ff>
then</FONT></SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><FONT
color=#000000> <BR></FONT><SPAN lang=en-us><FONT
color=#0000ff>
person.setClassName("Math");</FONT></SPAN></FONT></FONT><FONT
face="Courier New"><FONT size=2><FONT color=#000000> <BR></FONT><SPAN
lang=en-us><FONT
color=#0000ff>
update(person);</FONT></SPAN></FONT></FONT><FONT face="Courier New"><FONT
size=2><FONT color=#000000> <BR></FONT><SPAN lang=en-us><FONT
color=#0000ff> end</FONT></SPAN><FONT color=#000000>
</FONT></FONT></FONT></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=465015110-11092008><FONT face="Courier New"
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=465015110-11092008>
<DIV dir=ltr align=left><SPAN class=465015110-11092008><FONT color=#0000ff><FONT
face="Courier New" size=2>rule "And now, time for something completely
different"</FONT><FONT face="Courier New"><FONT size=2><FONT color=#000000>
<BR></FONT><SPAN lang=en-us><FONT color=#0000ff>
no-loop</FONT></SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><FONT
color=#000000> <BR></FONT><SPAN lang=en-us><FONT
color=#0000ff>
when</FONT></SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><FONT
color=#000000> <BR></FONT><SPAN lang=en-us><FONT
color=#0000ff>
person : Person(likesMath == true)</FONT></SPAN></FONT></FONT><FONT
face="Courier New"><FONT size=2><FONT color=#000000> <BR></FONT><SPAN
lang=en-us><FONT color=#0000ff>
then</FONT></SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><FONT
color=#000000> <BR></FONT><SPAN lang=en-us><FONT
color=#0000ff> PreferredClass
p = new PreferredClass("Math");</FONT></SPAN></FONT></FONT></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=465015110-11092008><FONT color=#0000ff><SPAN
lang=en-us><FONT face="Courier New" color=#0000ff size=2><SPAN lang=en-us><FONT
color=#0000ff> p.setPerson(person);</FONT></SPAN></FONT></SPAN></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=465015110-11092008><FONT color=#0000ff><SPAN
lang=en-us><FONT face="Courier New" color=#0000ff size=2><SPAN
lang=en-us></SPAN>
insert(p);</FONT></SPAN><FONT face="Courier New"><FONT size=2><FONT
color=#000000> <BR></FONT><SPAN lang=en-us><FONT
color=#0000ff> end</FONT></SPAN><FONT color=#000000>
</FONT></FONT></FONT></FONT></SPAN></DIV></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=465015110-11092008><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=465015110-11092008><FONT face=Arial
color=#0000ff size=2></FONT></SPAN><SPAN class=465015110-11092008><FONT
face=Arial color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=465015110-11092008><FONT face=Arial
color=#0000ff size=2>Cheers,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=465015110-11092008><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=465015110-11092008><FONT face=Arial
color=#0000ff size=2>Mike</FONT></SPAN></DIV><BR>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> rules-users-bounces@lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] <B>On Behalf Of </B>Shyam, Pallav
(MSCIBARRA)<BR><B>Sent:</B> 11 September 2008 11:40<BR><B>To:</B>
rules-users@lists.jboss.org<BR><B>Subject:</B> Re: [rules-users] Update vs
insert<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV>
<P><FONT face=Arial color=navy size=2>Very strange. The facts are passed into
the WM by-reference. Therefore the query should work after calling the
person.setClassName("Math") on the fact. And this should work without calling
the insert or update.<BR><BR>This leaves me guessing that the query does not
work on the facts directly, instead they work on shadow facts.
<BR><BR><BR></FONT></P>
<P>
<HR tabIndex=-1 align=center width="100%" SIZE=2>
<FONT face=Tahoma size=2><B>From</B>: rules-users-bounces@lists.jboss.org
<RULES-USERS-BOUNCES@LISTS.JBOSS.ORG><BR><B>To</B>: Rules Users List
<RULES-USERS@LISTS.JBOSS.ORG><BR><B>Sent</B>: Thu Sep 11 04:41:37
2008<BR><B>Subject</B>: [rules-users] Update vs insert <BR></FONT>
<P></P><!-- Converted from text/rtf format -->
<P><SPAN lang=en-us><FONT face=Arial size=2>Hello,</FONT></SPAN> </P>
<P><SPAN lang=en-us><FONT face=Arial size=2> What is the
difference between calling insert and update in a rule file? When I use insert
my queries don’t work, but if I use update they seem to. I don't mind using
update, but I would like to understand the difference between the two. Here is
my rule file.</FONT></SPAN></P>
<P><SPAN lang=en-us><FONT face=Arial size=2> </FONT><FONT
face=Arial color=#0000ff size=2> rule "Add person to math class"</FONT></SPAN>
<BR><SPAN lang=en-us><FONT face=Arial color=#0000ff size=2>
no-loop</FONT></SPAN> <BR><SPAN lang=en-us><FONT face=Arial color=#0000ff
size=2> when</FONT></SPAN> <BR><SPAN
lang=en-us><FONT face=Arial color=#0000ff
size=2>
person : Person(likesMath == true)</FONT></SPAN> <BR><SPAN lang=en-us><FONT
face=Arial color=#0000ff size=2>
then</FONT></SPAN> <BR><SPAN lang=en-us><FONT face=Arial color=#0000ff
size=2>
person.setClassName("Math");</FONT></SPAN> <BR><SPAN lang=en-us><FONT
face=Arial color=#0000ff
size=2>
insert(person);</FONT></SPAN> <BR><SPAN lang=en-us><FONT face=Arial
color=#0000ff size=2> end</FONT></SPAN> </P>
<P><SPAN lang=en-us><FONT face=Arial size=2> I also have a
query:</FONT></SPAN> </P>
<P><SPAN lang=en-us><FONT face=Arial size=2> </FONT><FONT
face=Arial color=#0000ff size=2>query getPeopleForClass(String
_className)</FONT></SPAN> <BR><SPAN lang=en-us><FONT face=Arial color=#0000ff
size=2> Person(className ==
_className)</FONT></SPAN> <BR><SPAN lang=en-us><FONT face=Arial color=#0000ff
size=2> end</FONT></SPAN> </P>
<P><SPAN lang=en-us><FONT face=Arial size=2> When I add two facts
to working memory, where the likesMath attribute is true, then run my query I
get zero results back. When I change the rule, </FONT><FONT face=Arial
color=#0000ff size=2>"Add person to math class",</FONT><FONT face=Arial
size=2> to use update(person) instead of insert(person) two students are
returned.</FONT></SPAN></P>
<P><SPAN lang=en-us><FONT face=Arial size=2> Any help would be
appreciated.</FONT></SPAN> </P>
<P><SPAN lang=en-us><FONT face=Arial size=2>Thanks,</FONT></SPAN> <BR><SPAN
lang=en-us><FONT face=Arial size=2>Dan</FONT></SPAN> </P><BR>
<P><SPAN lang=en-us><FONT face=Arial size=2>Daniel Quinn</FONT></SPAN>
<BR><SPAN lang=en-us><FONT face=Arial size=2>Fedex - Custom
Critical</FONT></SPAN> <BR><SPAN lang=en-us><FONT face=Arial size=2>Software
Specialist I</FONT></SPAN> <BR><SPAN lang=en-us><FONT face=Arial
size=2>234.310.4090(x2586)</FONT></SPAN> </P>
<P><SPAN lang=en-us><FONT face=Arial size=2>-----Original
Message-----</FONT></SPAN> <BR><SPAN lang=en-us><FONT face=Arial size=2>From:
rules-users-bounces@lists.jboss.org [</FONT></SPAN><A
href="mailto:rules-users-bounces@lists.jboss.org"><SPAN lang=en-us><U><FONT
face=Arial color=#0000ff
size=2>mailto:rules-users-bounces@lists.jboss.org</FONT></U></SPAN></A><SPAN
lang=en-us><FONT face=Arial size=2>] On Behalf Of
thomaskukofka@web.de</FONT></SPAN></P>
<P><SPAN lang=en-us><FONT face=Arial size=2>Sent: Wednesday, September 10,
2008 2:27 PM</FONT></SPAN> <BR><SPAN lang=en-us><FONT face=Arial size=2>To:
rules-users@lists.jboss.org</FONT></SPAN> <BR><SPAN lang=en-us><FONT
face=Arial size=2>Subject: [rules-users] Re: looping problem</FONT></SPAN>
</P>
<P><SPAN lang=en-us><FONT face=Arial size=2>Hello,</FONT></SPAN> </P>
<P><SPAN lang=en-us><FONT face=Arial size=2>thanks that works. I just forgot
to set the focus in the init rule..</FONT></SPAN> </P>
<P><SPAN lang=en-us><FONT face=Arial size=2>Regards</FONT></SPAN> <BR><SPAN
lang=en-us><FONT face=Arial size=2>Thomas</FONT></SPAN> <BR><SPAN
lang=en-us><FONT face=Arial
size=2>_______________________________________________</FONT></SPAN> <BR><SPAN
lang=en-us><FONT face=Arial size=2>rules-users mailing list</FONT></SPAN>
<BR><SPAN lang=en-us><FONT face=Arial
size=2>rules-users@lists.jboss.org</FONT></SPAN> <BR><SPAN
lang=en-us></SPAN><A
href="https://lists.jboss.org/mailman/listinfo/rules-users"><SPAN
lang=en-us><U><FONT face=Arial color=#0000ff
size=2>https://lists.jboss.org/mailman/listinfo/rules-users</FONT></U></SPAN></A><SPAN
lang=en-us></SPAN> </P><BR></DIV>
<DIV>
<HR>
</DIV>
<P class=BulletedList
style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0in; mso-list: none; tab-stops: .5in"><SPAN
style="FONT-SIZE: 8pt; COLOR: gray; mso-bidi-font-family: Arial"><FONT
face=Arial color=gray size=1>NOTICE: If received in error, please destroy and
notify sender. Sender does not intend to waive confidentiality or privilege.
Use of this email is prohibited when received in error.</FONT></SPAN></P>
<DIV></DIV></BLOCKQUOTE></BODY></HTML>