<div dir="ltr"><div><span style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif">Hi everybody! </span><br></div>
<br style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13px"><span style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13px">For demo purposes, there's a class Book that goes as follows: </span><br style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13px">
<br style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13px"><pre style="color:rgb(0,0,0)">@Entity
@Table(name="book")
public class Book implements Serializable {
@Id
private String id;
private String title;
private String description;
private Float unitcost;
private String isbn;
private Integer nbofpages;
//Default ctor... getters & setters... toString...
}</pre><br style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13px"><span style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13px">I created a basic rule that checks if Book's title contains "Java" it's left in the session, otherwise it's retracted: </span><br style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13px">
<br style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13px"><pre style="color:rgb(0,0,0)">dialect "mvel"
import com.arcady.*;
rule "not a java book"
when
b:Book(title.contains("Java")==false)
then
System.out.println("Yet another boring book... Retracting: " + b.toString());
retract(b);
end</pre><br style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13px"><span style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13px">So far, so good. Problem now is when trying to persist all the Drools + Book's instances that still remained in the session into MySQL database (I used</span><a href="http://packtlib.packtpub.com/library/9781849511964/ch02lvl1sec17" rel="nofollow" link="external" style="font-size:13px;color:rgb(85,26,139);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif" target="_blank">http://packtlib.packtpub.com/library/9781849511964/ch02lvl1sec17</a><span style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13px"> as reference). </span><br style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13px">
<br style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13px"><span style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13px">After inserting 4 books as listed below into the session and firing all rules: </span><br style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13px">
<pre style="color:rgb(0,0,0)">Book javaBook1 = new Book("Java EE 7");
Book javaBook2 = new Book("Java Persistence API 2.1");
Book javaBook3 = new Book("Java SE 8");
Book csharpBook1 = new Book("C# 5.0");</pre><br style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13px"><span style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13px">I get in the output: </span><br style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13px">
<pre style="color:rgb(0,0,0)">Hibernate: insert into SessionInfo (lastModificationDate, rulesByteArray, startDate, OPTLOCK) values (?, ?, ?, ?)
Hibernate: update SessionInfo set lastModificationDate=?, rulesByteArray=?, startDate=?, OPTLOCK=? where id=? and OPTLOCK=?
Hibernate: update SessionInfo set lastModificationDate=?, rulesByteArray=?, startDate=?, OPTLOCK=? where id=? and OPTLOCK=?
Hibernate: update SessionInfo set lastModificationDate=?, rulesByteArray=?, startDate=?, OPTLOCK=? where id=? and OPTLOCK=?
Yet another boring book... Retracting: Book{id=304e76fd-3d9a-479b-b22d-a774d721df65, title='C# 5.0', description='Blabla', unitcost=0.0, isbn='ABC123', nbofpages=12345}
Hibernate: update SessionInfo set lastModificationDate=?, rulesByteArray=?, startDate=?, OPTLOCK=? where id=? and OPTLOCK=?</pre><br style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13px">
<span style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13px">Thus the session was persisted 4 times, and indeed that's what also shows in the database in the sessioninfo table. </span><br style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13px">
<br style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13px"><span style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13px">Problem is Book's table is created with all the correct columns automatically but remains empty... </span><br style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13px">
<br style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13px"><span style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13px">What do you think causes this? </span><br style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13px">
<br style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13px"><span style="color:rgb(0,0,0);font-family:Verdana,Geneva,Helvetica,Arial,sans-serif;font-size:13px">Thanks a lot!</span><br clear="all">
<div><br></div>-- <br><div dir="ltr">Regards,<br>Arcady Trembovler<br><br></div>
</div>