[rules-users] Calling EntityManager from DRL--DRL Parser attempts to parse sql query instead of passing as string to createNativeQuery method

David Siefert siefert.david.mailinglist at gmail.com
Mon Jul 7 10:31:17 EDT 2008


Hello,

I am trying to use the EntityManager within a rule.  I pass the
EntityManager instance in from my test (currently just a mock of the
interface using EasyMock) using setGlobal("em", entitymanager);

so in my drls, I have:

<code>
global javax.persistence.EntityManager em;
</code>

And then I use this in my LHS of the rule with a from:

<code>
rule "query-db"
  when
    SampleObject(property from (em.createNativeQuery("select PROP from
SAMPLEOBJECT").getResultList()))
  then
    System.out.println("Got an object!");
end
</code>

However, when I run my JUnit test, I get an error saying "unexpected token
'PROP'".  So it looks like the Drools parser is trying to interpret what is
in my string.  Is there a special way to pass a string to the Java
operation?  Or can I simply not do this?  How would I be able to get a
result set from the db to use in pattern matching?  The rule is dependent
upon data from a table to make a decision.

Thanks,

David Siefert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20080707/08a5ea1e/attachment.html 


More information about the rules-users mailing list