Re: [rules-users] Hibernate proxy objects equality tests failing in Drools 5
You can't do "participante.id == $participante.id "? --- On Wed, 5/6/09, Guto wrote: > From: Guto > Subject: Re: [rules-users] Hibernate proxy objects equality tests failing in > Drools 5 > To: "Rules Users List" > Date: Wednesday, May 6, 2009, 7:43 AM > I don´t have a clue why is not working eather. > > Unfortunelly I can´t really rely on a.id == b.id ´cause I > have rules like: > $participante:Participante() && $participacoes: > ArrayList(size == 0) from > collect(ParticipacaoCiclo(participante == $participante > && saidaPosto == > null && periodo == 1 )) > > Do eager fetching, will really reduce my perfomace, since > most of my > collection properties have a huge amount of data (I don´t > use that data > inside the drools session, I don´t need them). > > I have 2 clients one is an UnitTest that access the EJB and > the other is > an JSF 1.2 webclient (the real application itself). I´m > not using groovy > (not in this project, however I found that really > interesting). > > thanks. > > just a question (==) will be translated to (equals) right? > > > > > > With the new hibernate jars and the migration to the > new Javassist, > > what hibernate is essentially doing is dynamically > generating > > hibernate proxy objects that should subclass the > original file. > > Here's the interesting part. > > > > In groovy, comparing two hibernate objects: > > > > a.a == b.a > > > > works fine when they are the same type of object. > Under groovy, "==" > > uses "equals()" to do the comparison. That > appears to work all good. > > However, taking these same two objects into Drools and > comparing their > > subproperty when they are lazily loaded will cause the > problems that > > a.a no longer equals to b.a. Yet under groovy, it > still says they are > > equal. > > > > There could be one of 2-3 things that can be done to > fix this, which I > > haven't entirely tried. > > > > 1) implement your own version of equals() and > hashCode() and use the > > instanceOf() hibernate util method to do comparison. > Sadly, I have > > over 50 domains objects and I'm hoping not to have > to implement all > > the methods. > > > > 2) do a eager fetch of the properties. This is > probably the best and > > easy way, but I am getting this working well under > Grails/groovy. > > Somehow it's still fetching them as proxy objects, > but just loaded. > > Either that or the eager fetching isn't even > working (I've yet to > > fully test this yet with hibernate logging turned on > to check). > > > > 3) use each domain's identity or some unique > constraint to do the > > equality check. This is my current > "cheating" way of getting around > > the problem. I simply use a.a.id == b.a.id. However, > this poses an > > additional complexity where I actually have to do null > checks for the > > property. Otherwise, I'd get NPEs all over the > place. > > > > At the end of the day, I don't see why Drools > cannot see proxy objects > > as equal. The only way I can think of is that there > is some sort of > > direct object/class type check in Drools that's > causing it not to > > realize that two objects are equal. But I could be > wrong, and I hope > > I'm wrong. :) > > > > -Chris > > > > On May 4, 2009, at 1:29 PM, Guto wrote: > > > >> Thanks Greg, > >> > >> But it´s not a lazy loading problem at all. I am > not using any kind of > >> lazy attribute inside the statefull drools > session... > >> > >> Unfortunelly, i´ve just upgrade from drools 4GA > to 5CR1 and the > >> problem > >> persist. Now I will try to make CLONES of the > objects the came from > >> the > >> bank, just to see if that (temporary) solution > works. > >> > >>> > >>> Do you need the lazy loading functionality > that proxies provide? > >>> It seems > >>> to me that if you have an EJB call that's > providing the objects > >>> loaded > >>> from hibernate, that's probably not the > case. (i.e. once the > >>> objects are > >>> loaded and returned by the EJB method, the > hibernate session may no > >>> longer > >>> be available, so lazy loading could fail > anyway.) If you have > >>> access to > >
Re: [rules-users] Hibernate proxy objects equality tests failing in Drools 5
Hi, Using RuleFlow in Drools 5 into a action element, how can I read or get the classes that were in working memory ? Thanks, Kevin ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Hibernate proxy objects equality tests failing in Drools 5
I don´t have a clue why is not working eather. Unfortunelly I can´t really rely on a.id == b.id ´cause I have rules like: $participante:Participante() && $participacoes: ArrayList(size == 0) from collect(ParticipacaoCiclo(participante == $participante && saidaPosto == null && periodo == 1 )) Do eager fetching, will really reduce my perfomace, since most of my collection properties have a huge amount of data (I don´t use that data inside the drools session, I don´t need them). I have 2 clients one is an UnitTest that access the EJB and the other is an JSF 1.2 webclient (the real application itself). I´m not using groovy (not in this project, however I found that really interesting). thanks. just a question (==) will be translated to (equals) right? > With the new hibernate jars and the migration to the new Javassist, > what hibernate is essentially doing is dynamically generating > hibernate proxy objects that should subclass the original file. > Here's the interesting part. > > In groovy, comparing two hibernate objects: > > a.a == b.a > > works fine when they are the same type of object. Under groovy, "==" > uses "equals()" to do the comparison. That appears to work all good. > However, taking these same two objects into Drools and comparing their > subproperty when they are lazily loaded will cause the problems that > a.a no longer equals to b.a. Yet under groovy, it still says they are > equal. > > There could be one of 2-3 things that can be done to fix this, which I > haven't entirely tried. > > 1) implement your own version of equals() and hashCode() and use the > instanceOf() hibernate util method to do comparison. Sadly, I have > over 50 domains objects and I'm hoping not to have to implement all > the methods. > > 2) do a eager fetch of the properties. This is probably the best and > easy way, but I am getting this working well under Grails/groovy. > Somehow it's still fetching them as proxy objects, but just loaded. > Either that or the eager fetching isn't even working (I've yet to > fully test this yet with hibernate logging turned on to check). > > 3) use each domain's identity or some unique constraint to do the > equality check. This is my current "cheating" way of getting around > the problem. I simply use a.a.id == b.a.id. However, this poses an > additional complexity where I actually have to do null checks for the > property. Otherwise, I'd get NPEs all over the place. > > At the end of the day, I don't see why Drools cannot see proxy objects > as equal. The only way I can think of is that there is some sort of > direct object/class type check in Drools that's causing it not to > realize that two objects are equal. But I could be wrong, and I hope > I'm wrong. :) > > -Chris > > On May 4, 2009, at 1:29 PM, Guto wrote: > >> Thanks Greg, >> >> But it´s not a lazy loading problem at all. I am not using any kind of >> lazy attribute inside the statefull drools session... >> >> Unfortunelly, i´ve just upgrade from drools 4GA to 5CR1 and the >> problem >> persist. Now I will try to make CLONES of the objects the came from >> the >> bank, just to see if that (temporary) solution works. >> >>> >>> Do you need the lazy loading functionality that proxies provide? >>> It seems >>> to me that if you have an EJB call that's providing the objects >>> loaded >>> from hibernate, that's probably not the case. (i.e. once the >>> objects are >>> loaded and returned by the EJB method, the hibernate session may no >>> longer >>> be available, so lazy loading could fail anyway.) If you have >>> access to >>> the hibernate mapping just set lazy="false" on your class mappings. >>> >>> Not to say that this use case shouldn't be addressed with drools, >>> but if >>> you're under a deadline... :) >>> >>> --- On Mon, 5/4/09, Guto wrote: >>> >>>> From: Guto >>>> Subject: Re: [rules-users] Hibernate proxy objects equality tests >>>> failing in Drools 5 >>>> To: "Rules Users List" >>>> Date: Monday, May 4, 2009, 2:42 PM >>>> Just now I notice one thing. The application that i am >>>> building is >>>> compleatly EJB centric. I have um EJB project that usually >>>> do all the >>>> database stuff, and another EJB project for the drools >>>> rules. Lets call >>>> them >>>> EJB-DATA and EJB-DROOLS. When the client calls for an >
Re: [rules-users] Hibernate proxy objects equality tests failing in Drools 5
Testing, I don´t think my 2 recent messages were sended to the list!!! > Oh, and a couple other things I forgot to mention. > > I believe Hibernate by default will lazily load all association > objects. You have to explicitly set the lazy loading to false in > order to get eager fetching. I don't consider to be ideal as I have a > pricing object that contains many optional attributes to about 10-15 > tables out there. > > Also, there appears one way to fix this under Groovy. If you assign a > proxy hibernate object to a class property that explicitly define the > type of the object, then groovy will actually automatically recast it > as that type. For example: > > class MyDomainA { >String b > } > > class MyDomainB { >MyDomainA a // this will get proxied by hibernate > } > > class MyPOJO { >MyDomainA a > } > > if I assign it as follows: > > def pojo = new MyPOJO() > > pojo = myDomainB.a // groovy will autoconvert the proxied object to > the real class and store it as MyDomainA in MyPOJO. > > Drools, under this condition, will be fine with it. However, this is > not ideal as that means I need to basically create a duplicate POJO > object to store all of the hibernate domain objects. No good. > > oh well, back to my a.id == b.id. :) > > -Chris > > > On May 4, 2009, at 1:29 PM, Guto wrote: > >> Thanks Greg, >> >> But it´s not a lazy loading problem at all. I am not using any kind of >> lazy attribute inside the statefull drools session... >> >> Unfortunelly, i´ve just upgrade from drools 4GA to 5CR1 and the >> problem >> persist. Now I will try to make CLONES of the objects the came from >> the >> bank, just to see if that (temporary) solution works. >> >>> >>> Do you need the lazy loading functionality that proxies provide? >>> It seems >>> to me that if you have an EJB call that's providing the objects >>> loaded >>> from hibernate, that's probably not the case. (i.e. once the >>> objects are >>> loaded and returned by the EJB method, the hibernate session may no >>> longer >>> be available, so lazy loading could fail anyway.) If you have >>> access to >>> the hibernate mapping just set lazy="false" on your class mappings. >>> >>> Not to say that this use case shouldn't be addressed with drools, >>> but if >>> you're under a deadline... :) >>> >>> --- On Mon, 5/4/09, Guto wrote: >>> >>>> From: Guto >>>> Subject: Re: [rules-users] Hibernate proxy objects equality tests >>>> failing in Drools 5 >>>> To: "Rules Users List" >>>> Date: Monday, May 4, 2009, 2:42 PM >>>> Just now I notice one thing. The application that i am >>>> building is >>>> compleatly EJB centric. I have um EJB project that usually >>>> do all the >>>> database stuff, and another EJB project for the drools >>>> rules. Lets call >>>> them >>>> EJB-DATA and EJB-DROOLS. When the client calls for an >>>> specific data that >>>> must be threated thru the Drools rules it calls an >>>> Stateless method from >>>> EJB-DATA, inside the method, it gather the necessarie >>>> parameter >>>> information and them inside the EJB-DATA method it calls >>>> the EJB-DROOLS. >>>> (hoping not been confusing) >>>> >>>> (if you are using an fixed space font, here comes the >>>> sequence) >>>> >>>> Client --> EJB-DATA (gather information inside) --> >>>> EJB-DROOLS >>>> <-- return to Client data from EJB-DROOLS<-- >>>> return to EJB-DATA >>>> >>>> Now looking over my two projects, I notice that I make them >>>> apart so one >>>> could evolve with interfering the other. >>>> >>>> When I call EJB-DROOLS directly from an UNIT-TEST client >>>> with pojos >>>> parameters intantiated by the test, it pass. >>>> >>>> When I call EJB-DATA from an UNIT-TEST client (pojos >>>> created inside this), >>>> first i was getting an CORBA exception ´cause of a >>>> ClassNotFoundException >>>> for the hibernate PersistenceBag. >>>> >>>> That´s the way i figure out that my objects are bagged or >>>> proxied thru >>>> hibernate. >>>> >>>> I´ve tried to use th
Re: [rules-users] Hibernate proxy objects equality tests failing in Drools 5
With the new hibernate jars and the migration to the new Javassist, what hibernate is essentially doing is dynamically generating hibernate proxy objects that should subclass the original file. Here's the interesting part. In groovy, comparing two hibernate objects: a.a == b.a works fine when they are the same type of object. Under groovy, "==" uses "equals()" to do the comparison. That appears to work all good. However, taking these same two objects into Drools and comparing their subproperty when they are lazily loaded will cause the problems that a.a no longer equals to b.a. Yet under groovy, it still says they are equal. There could be one of 2-3 things that can be done to fix this, which I haven't entirely tried. 1) implement your own version of equals() and hashCode() and use the instanceOf() hibernate util method to do comparison. Sadly, I have over 50 domains objects and I'm hoping not to have to implement all the methods. 2) do a eager fetch of the properties. This is probably the best and easy way, but I am getting this working well under Grails/groovy. Somehow it's still fetching them as proxy objects, but just loaded. Either that or the eager fetching isn't even working (I've yet to fully test this yet with hibernate logging turned on to check). 3) use each domain's identity or some unique constraint to do the equality check. This is my current "cheating" way of getting around the problem. I simply use a.a.id == b.a.id. However, this poses an additional complexity where I actually have to do null checks for the property. Otherwise, I'd get NPEs all over the place. At the end of the day, I don't see why Drools cannot see proxy objects as equal. The only way I can think of is that there is some sort of direct object/class type check in Drools that's causing it not to realize that two objects are equal. But I could be wrong, and I hope I'm wrong. :) -Chris On May 4, 2009, at 1:29 PM, Guto wrote: Thanks Greg, But it´s not a lazy loading problem at all. I am not using any kind of lazy attribute inside the statefull drools session... Unfortunelly, i´ve just upgrade from drools 4GA to 5CR1 and the problem persist. Now I will try to make CLONES of the objects the came from the bank, just to see if that (temporary) solution works. Do you need the lazy loading functionality that proxies provide? It seems to me that if you have an EJB call that's providing the objects loaded from hibernate, that's probably not the case. (i.e. once the objects are loaded and returned by the EJB method, the hibernate session may no longer be available, so lazy loading could fail anyway.) If you have access to the hibernate mapping just set lazy="false" on your class mappings. Not to say that this use case shouldn't be addressed with drools, but if you're under a deadline... :) --- On Mon, 5/4/09, Guto wrote: From: Guto Subject: Re: [rules-users] Hibernate proxy objects equality tests failing in Drools 5 To: "Rules Users List" Date: Monday, May 4, 2009, 2:42 PM Just now I notice one thing. The application that i am building is compleatly EJB centric. I have um EJB project that usually do all the database stuff, and another EJB project for the drools rules. Lets call them EJB-DATA and EJB-DROOLS. When the client calls for an specific data that must be threated thru the Drools rules it calls an Stateless method from EJB-DATA, inside the method, it gather the necessarie parameter information and them inside the EJB-DATA method it calls the EJB-DROOLS. (hoping not been confusing) (if you are using an fixed space font, here comes the sequence) Client --> EJB-DATA (gather information inside) --> EJB-DROOLS <-- return to Client data from EJB-DROOLS<-- return to EJB-DATA Now looking over my two projects, I notice that I make them apart so one could evolve with interfering the other. When I call EJB-DROOLS directly from an UNIT-TEST client with pojos parameters intantiated by the test, it pass. When I call EJB-DATA from an UNIT-TEST client (pojos created inside this), first i was getting an CORBA exception ´cause of a ClassNotFoundException for the hibernate PersistenceBag. That´s the way i figure out that my objects are bagged or proxied thru hibernate. I´ve tried to use the EntityManager.clear() (EJB3-JPA) to clean the pojos before send it and make them more like the ones from the first unit-test, but even so it´s not working. Then, possible solutions: 1) Make equality test works from objects that came from hibernate from jpa. 2) Kill the proxies and make them simple objects (not hibernate derivated). 3) don´t know, but i´m been realy in a deadline here. again thanks for anyone in advance ! -- Guto Maia Consultor de TI / Desenvolvedor CSM - SCJP- SCWCD - SCBCD
Re: [rules-users] Hibernate proxy objects equality tests failing in Drools 5
Oh, and a couple other things I forgot to mention. I believe Hibernate by default will lazily load all association objects. You have to explicitly set the lazy loading to false in order to get eager fetching. I don't consider to be ideal as I have a pricing object that contains many optional attributes to about 10-15 tables out there. Also, there appears one way to fix this under Groovy. If you assign a proxy hibernate object to a class property that explicitly define the type of the object, then groovy will actually automatically recast it as that type. For example: class MyDomainA { String b } class MyDomainB { MyDomainA a // this will get proxied by hibernate } class MyPOJO { MyDomainA a } if I assign it as follows: def pojo = new MyPOJO() pojo = myDomainB.a // groovy will autoconvert the proxied object to the real class and store it as MyDomainA in MyPOJO. Drools, under this condition, will be fine with it. However, this is not ideal as that means I need to basically create a duplicate POJO object to store all of the hibernate domain objects. No good. oh well, back to my a.id == b.id. :) -Chris On May 4, 2009, at 1:29 PM, Guto wrote: Thanks Greg, But it´s not a lazy loading problem at all. I am not using any kind of lazy attribute inside the statefull drools session... Unfortunelly, i´ve just upgrade from drools 4GA to 5CR1 and the problem persist. Now I will try to make CLONES of the objects the came from the bank, just to see if that (temporary) solution works. Do you need the lazy loading functionality that proxies provide? It seems to me that if you have an EJB call that's providing the objects loaded from hibernate, that's probably not the case. (i.e. once the objects are loaded and returned by the EJB method, the hibernate session may no longer be available, so lazy loading could fail anyway.) If you have access to the hibernate mapping just set lazy="false" on your class mappings. Not to say that this use case shouldn't be addressed with drools, but if you're under a deadline... :) --- On Mon, 5/4/09, Guto wrote: From: Guto Subject: Re: [rules-users] Hibernate proxy objects equality tests failing in Drools 5 To: "Rules Users List" Date: Monday, May 4, 2009, 2:42 PM Just now I notice one thing. The application that i am building is compleatly EJB centric. I have um EJB project that usually do all the database stuff, and another EJB project for the drools rules. Lets call them EJB-DATA and EJB-DROOLS. When the client calls for an specific data that must be threated thru the Drools rules it calls an Stateless method from EJB-DATA, inside the method, it gather the necessarie parameter information and them inside the EJB-DATA method it calls the EJB-DROOLS. (hoping not been confusing) (if you are using an fixed space font, here comes the sequence) Client --> EJB-DATA (gather information inside) --> EJB-DROOLS <-- return to Client data from EJB-DROOLS<-- return to EJB-DATA Now looking over my two projects, I notice that I make them apart so one could evolve with interfering the other. When I call EJB-DROOLS directly from an UNIT-TEST client with pojos parameters intantiated by the test, it pass. When I call EJB-DATA from an UNIT-TEST client (pojos created inside this), first i was getting an CORBA exception ´cause of a ClassNotFoundException for the hibernate PersistenceBag. That´s the way i figure out that my objects are bagged or proxied thru hibernate. I´ve tried to use the EntityManager.clear() (EJB3-JPA) to clean the pojos before send it and make them more like the ones from the first unit-test, but even so it´s not working. Then, possible solutions: 1) Make equality test works from objects that came from hibernate from jpa. 2) Kill the proxies and make them simple objects (not hibernate derivated). 3) don´t know, but i´m been realy in a deadline here. again thanks for anyone in advance ! -- Guto Maia Consultor de TI / Desenvolvedor CSM - SCJP- SCWCD - SCBCD - ZCE In fact, i´m really using JPA with hibernate as an provider. Could you send me your hibernate config? I will compare some proprieties of tyour hibernate.config with my persistence.xml. I plenty sure that the rule is ok, since it is working with the unit test. If you need any help to mimic what your using with JPA, just ask. Thanks anyway. I'm using non-proxied hibernate backed POJOs in drools with no problems. (THe pojos aer generaed by hbm2java.) I'll try configuring for proxies to see what happens. --- On Mon, 5/4/09, Gustavo Maia Neto wrote: From: Gustavo Maia Neto Subject: Re: [rules-users] Hibernate proxy objects equality tests failing in Drools 5 To: "Rules Users List" Date: Monday, May 4, 2009, 11:28 AM on this afternoon I will migrate to Drools 5 CR1, unfortunelly i'm not sure if it will solve my
Re: [rules-users] Hibernate proxy objects equality tests failing in Drools 5
Thanks Greg, But it´s not a lazy loading problem at all. I am not using any kind of lazy attribute inside the statefull drools session... Unfortunelly, i´ve just upgrade from drools 4GA to 5CR1 and the problem persist. Now I will try to make CLONES of the objects the came from the bank, just to see if that (temporary) solution works. > > Do you need the lazy loading functionality that proxies provide? It seems > to me that if you have an EJB call that's providing the objects loaded > from hibernate, that's probably not the case. (i.e. once the objects are > loaded and returned by the EJB method, the hibernate session may no longer > be available, so lazy loading could fail anyway.) If you have access to > the hibernate mapping just set lazy="false" on your class mappings. > > Not to say that this use case shouldn't be addressed with drools, but if > you're under a deadline... :) > > --- On Mon, 5/4/09, Guto wrote: > >> From: Guto >> Subject: Re: [rules-users] Hibernate proxy objects equality tests >> failing in Drools 5 >> To: "Rules Users List" >> Date: Monday, May 4, 2009, 2:42 PM >> Just now I notice one thing. The application that i am >> building is >> compleatly EJB centric. I have um EJB project that usually >> do all the >> database stuff, and another EJB project for the drools >> rules. Lets call >> them >> EJB-DATA and EJB-DROOLS. When the client calls for an >> specific data that >> must be threated thru the Drools rules it calls an >> Stateless method from >> EJB-DATA, inside the method, it gather the necessarie >> parameter >> information and them inside the EJB-DATA method it calls >> the EJB-DROOLS. >> (hoping not been confusing) >> >> (if you are using an fixed space font, here comes the >> sequence) >> >> Client --> EJB-DATA (gather information inside) --> >> EJB-DROOLS >><-- return to Client data from EJB-DROOLS<-- >> return to EJB-DATA >> >> Now looking over my two projects, I notice that I make them >> apart so one >> could evolve with interfering the other. >> >> When I call EJB-DROOLS directly from an UNIT-TEST client >> with pojos >> parameters intantiated by the test, it pass. >> >> When I call EJB-DATA from an UNIT-TEST client (pojos >> created inside this), >> first i was getting an CORBA exception ´cause of a >> ClassNotFoundException >> for the hibernate PersistenceBag. >> >> That´s the way i figure out that my objects are bagged or >> proxied thru >> hibernate. >> >> I´ve tried to use the EntityManager.clear() (EJB3-JPA) to >> clean the pojos >> before send it and make them more like the ones from the >> first unit-test, >> but even so it´s not working. >> >> Then, possible solutions: >> 1) Make equality test works from objects that came from >> hibernate from jpa. >> 2) Kill the proxies and make them simple objects (not >> hibernate derivated). >> 3) don´t know, but i´m been realy in a deadline here. >> >> >> again >> thanks for anyone in advance ! >> >> -- >> Guto Maia >> Consultor de TI / Desenvolvedor >> CSM - SCJP- SCWCD - SCBCD - ZCE >> >> >> >> >> >> > In fact, i´m really using JPA with hibernate as an >> provider. >> > >> > Could you send me your hibernate config? I will >> compare some proprieties >> > of tyour hibernate.config with my persistence.xml. >> > >> > I plenty sure that the rule is ok, since it is working >> with the unit test. >> > >> > If you need any help to mimic what your using with >> JPA, just ask. >> > >> > Thanks anyway. >> > >> > >> >> >> >> I'm using non-proxied hibernate backed POJOs >> in drools with no problems. >> >> (THe pojos aer generaed by hbm2java.) I'll >> try configuring for proxies >> >> to >> >> see what happens. >> >> >> >> >> >> --- On Mon, 5/4/09, Gustavo Maia Neto >> wrote: >> >> >> >>> From: Gustavo Maia Neto >> >>> Subject: Re: [rules-users] Hibernate proxy >> objects equality tests >> >>> failing in Drools 5 >> >>> To: "Rules Users List" >> >> >>> Date: Monday, May 4, 2009, 11:28 AM >> >>> on this afternoon I will migrate to Drools 5 >> CR1, >> >>> unfortunelly i'm not >> >
Re: [rules-users] Hibernate proxy objects equality tests failing in Drools 5
Do you need the lazy loading functionality that proxies provide? It seems to me that if you have an EJB call that's providing the objects loaded from hibernate, that's probably not the case. (i.e. once the objects are loaded and returned by the EJB method, the hibernate session may no longer be available, so lazy loading could fail anyway.) If you have access to the hibernate mapping just set lazy="false" on your class mappings. Not to say that this use case shouldn't be addressed with drools, but if you're under a deadline... :) --- On Mon, 5/4/09, Guto wrote: > From: Guto > Subject: Re: [rules-users] Hibernate proxy objects equality tests failing > in Drools 5 > To: "Rules Users List" > Date: Monday, May 4, 2009, 2:42 PM > Just now I notice one thing. The application that i am > building is > compleatly EJB centric. I have um EJB project that usually > do all the > database stuff, and another EJB project for the drools > rules. Lets call > them > EJB-DATA and EJB-DROOLS. When the client calls for an > specific data that > must be threated thru the Drools rules it calls an > Stateless method from > EJB-DATA, inside the method, it gather the necessarie > parameter > information and them inside the EJB-DATA method it calls > the EJB-DROOLS. > (hoping not been confusing) > > (if you are using an fixed space font, here comes the > sequence) > > Client --> EJB-DATA (gather information inside) --> > EJB-DROOLS ><-- return to Client data from EJB-DROOLS<-- > return to EJB-DATA > > Now looking over my two projects, I notice that I make them > apart so one > could evolve with interfering the other. > > When I call EJB-DROOLS directly from an UNIT-TEST client > with pojos > parameters intantiated by the test, it pass. > > When I call EJB-DATA from an UNIT-TEST client (pojos > created inside this), > first i was getting an CORBA exception ´cause of a > ClassNotFoundException > for the hibernate PersistenceBag. > > That´s the way i figure out that my objects are bagged or > proxied thru > hibernate. > > I´ve tried to use the EntityManager.clear() (EJB3-JPA) to > clean the pojos > before send it and make them more like the ones from the > first unit-test, > but even so it´s not working. > > Then, possible solutions: > 1) Make equality test works from objects that came from > hibernate from jpa. > 2) Kill the proxies and make them simple objects (not > hibernate derivated). > 3) don´t know, but i´m been realy in a deadline here. > > > again > thanks for anyone in advance ! > > -- > Guto Maia > Consultor de TI / Desenvolvedor > CSM - SCJP- SCWCD - SCBCD - ZCE > > > > > > > In fact, i´m really using JPA with hibernate as an > provider. > > > > Could you send me your hibernate config? I will > compare some proprieties > > of tyour hibernate.config with my persistence.xml. > > > > I plenty sure that the rule is ok, since it is working > with the unit test. > > > > If you need any help to mimic what your using with > JPA, just ask. > > > > Thanks anyway. > > > > > >> > >> I'm using non-proxied hibernate backed POJOs > in drools with no problems. > >> (THe pojos aer generaed by hbm2java.) I'll > try configuring for proxies > >> to > >> see what happens. > >> > >> > >> --- On Mon, 5/4/09, Gustavo Maia Neto > wrote: > >> > >>> From: Gustavo Maia Neto > >>> Subject: Re: [rules-users] Hibernate proxy > objects equality tests > >>> failing in Drools 5 > >>> To: "Rules Users List" > > >>> Date: Monday, May 4, 2009, 11:28 AM > >>> on this afternoon I will migrate to Drools 5 > CR1, > >>> unfortunelly i'm not > >>> sure if it will solve my problem. > >>> > >>> Does anyone else uses Drools with objects that > came from an > >>> hibernate, > >>> (proxies)? > >>> > >>> Also, i'm not using any proxy to fetch > lazy data inside > >>> my Drools > >>> stateful session. > >>> > >>> thanks > >>> > >>> Guto escreveu: > >>> > I was following that subject on markmail, > and them > >>> I've enterred the > >>> > user-group (so subject and body are > coppied from > >>> them). I've got the > >>> > exactly same problem. When I use th
Re: [rules-users] Hibernate proxy objects equality tests failing in Drools 5
Just now I notice one thing. The application that i am building is compleatly EJB centric. I have um EJB project that usually do all the database stuff, and another EJB project for the drools rules. Lets call them EJB-DATA and EJB-DROOLS. When the client calls for an specific data that must be threated thru the Drools rules it calls an Stateless method from EJB-DATA, inside the method, it gather the necessarie parameter information and them inside the EJB-DATA method it calls the EJB-DROOLS. (hoping not been confusing) (if you are using an fixed space font, here comes the sequence) Client --> EJB-DATA (gather information inside) --> EJB-DROOLS <-- return to Client data from EJB-DROOLS<-- return to EJB-DATA Now looking over my two projects, I notice that I make them apart so one could evolve with interfering the other. When I call EJB-DROOLS directly from an UNIT-TEST client with pojos parameters intantiated by the test, it pass. When I call EJB-DATA from an UNIT-TEST client (pojos created inside this), first i was getting an CORBA exception ´cause of a ClassNotFoundException for the hibernate PersistenceBag. That´s the way i figure out that my objects are bagged or proxied thru hibernate. I´ve tried to use the EntityManager.clear() (EJB3-JPA) to clean the pojos before send it and make them more like the ones from the first unit-test, but even so it´s not working. Then, possible solutions: 1) Make equality test works from objects that came from hibernate from jpa. 2) Kill the proxies and make them simple objects (not hibernate derivated). 3) don´t know, but i´m been realy in a deadline here. again thanks for anyone in advance ! -- Guto Maia Consultor de TI / Desenvolvedor CSM - SCJP- SCWCD - SCBCD - ZCE > In fact, i´m really using JPA with hibernate as an provider. > > Could you send me your hibernate config? I will compare some proprieties > of tyour hibernate.config with my persistence.xml. > > I plenty sure that the rule is ok, since it is working with the unit test. > > If you need any help to mimic what your using with JPA, just ask. > > Thanks anyway. > > >> >> I'm using non-proxied hibernate backed POJOs in drools with no problems. >> (THe pojos aer generaed by hbm2java.) I'll try configuring for proxies >> to >> see what happens. >> >> >> --- On Mon, 5/4/09, Gustavo Maia Neto wrote: >> >>> From: Gustavo Maia Neto >>> Subject: Re: [rules-users] Hibernate proxy objects equality tests >>> failing in Drools 5 >>> To: "Rules Users List" >>> Date: Monday, May 4, 2009, 11:28 AM >>> on this afternoon I will migrate to Drools 5 CR1, >>> unfortunelly i'm not >>> sure if it will solve my problem. >>> >>> Does anyone else uses Drools with objects that came from an >>> hibernate, >>> (proxies)? >>> >>> Also, i'm not using any proxy to fetch lazy data inside >>> my Drools >>> stateful session. >>> >>> thanks >>> >>> Guto escreveu: >>> > I was following that subject on markmail, and them >>> I've enterred the >>> > user-group (so subject and body are coppied from >>> them). I've got the >>> > exactly same problem. When I use the rules with >>> objects the came from the >>> > database (thru JPA hibernate provider), thouse rules >>> never match. When I >>> > do the same from Pojos hand made for unit test, it >>> work. >>> > >>> > I don't know what really happen, but i'm sure >>> that it is an equality test >>> > falling 'cause of the hibernate proxys. >>> > >>> > I don't get also any kind of error or exception, >>> since it ALL WORK. Just >>> > the rule isn't be acomplished. >>> > >>> > I'm using EJB3 + JPA (hibernate provider) and >>> Drools 4 GA; >>> > >>> > thanks in advance for any help >>> > >>> >>> ___ >>> rules-users mailing list >>> rules-users@lists.jboss.org >>> https://lists.jboss.org/mailman/listinfo/rules-users >> >> >> >> ___ >> rules-users mailing list >> rules-users@lists.jboss.org >> https://lists.jboss.org/mailman/listinfo/rules-users >> > > > -- > Guto Maia > Consultor de TI / Desenvolvedor > CSM - SCJP- SCWCD - SCBCD - ZCE > > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users > ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Hibernate proxy objects equality tests failing in Drools 5
In fact, i´m really using JPA with hibernate as an provider. Could you send me your hibernate config? I will compare some proprieties of tyour hibernate.config with my persistence.xml. I plenty sure that the rule is ok, since it is working with the unit test. If you need any help to mimic what your using with JPA, just ask. Thanks anyway. > > I'm using non-proxied hibernate backed POJOs in drools with no problems. > (THe pojos aer generaed by hbm2java.) I'll try configuring for proxies to > see what happens. > > > --- On Mon, 5/4/09, Gustavo Maia Neto wrote: > >> From: Gustavo Maia Neto >> Subject: Re: [rules-users] Hibernate proxy objects equality tests >> failing in Drools 5 >> To: "Rules Users List" >> Date: Monday, May 4, 2009, 11:28 AM >> on this afternoon I will migrate to Drools 5 CR1, >> unfortunelly i'm not >> sure if it will solve my problem. >> >> Does anyone else uses Drools with objects that came from an >> hibernate, >> (proxies)? >> >> Also, i'm not using any proxy to fetch lazy data inside >> my Drools >> stateful session. >> >> thanks >> >> Guto escreveu: >> > I was following that subject on markmail, and them >> I've enterred the >> > user-group (so subject and body are coppied from >> them). I've got the >> > exactly same problem. When I use the rules with >> objects the came from the >> > database (thru JPA hibernate provider), thouse rules >> never match. When I >> > do the same from Pojos hand made for unit test, it >> work. >> > >> > I don't know what really happen, but i'm sure >> that it is an equality test >> > falling 'cause of the hibernate proxys. >> > >> > I don't get also any kind of error or exception, >> since it ALL WORK. Just >> > the rule isn't be acomplished. >> > >> > I'm using EJB3 + JPA (hibernate provider) and >> Drools 4 GA; >> > >> > thanks in advance for any help >> > >> >> ___ >> rules-users mailing list >> rules-users@lists.jboss.org >> https://lists.jboss.org/mailman/listinfo/rules-users > > > > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users > -- Guto Maia Consultor de TI / Desenvolvedor CSM - SCJP- SCWCD - SCBCD - ZCE ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Hibernate proxy objects equality tests failing in Drools 5
I'm using non-proxied hibernate backed POJOs in drools with no problems. (THe pojos aer generaed by hbm2java.) I'll try configuring for proxies to see what happens. --- On Mon, 5/4/09, Gustavo Maia Neto wrote: > From: Gustavo Maia Neto > Subject: Re: [rules-users] Hibernate proxy objects equality tests failing in > Drools 5 > To: "Rules Users List" > Date: Monday, May 4, 2009, 11:28 AM > on this afternoon I will migrate to Drools 5 CR1, > unfortunelly i'm not > sure if it will solve my problem. > > Does anyone else uses Drools with objects that came from an > hibernate, > (proxies)? > > Also, i'm not using any proxy to fetch lazy data inside > my Drools > stateful session. > > thanks > > Guto escreveu: > > I was following that subject on markmail, and them > I've enterred the > > user-group (so subject and body are coppied from > them). I've got the > > exactly same problem. When I use the rules with > objects the came from the > > database (thru JPA hibernate provider), thouse rules > never match. When I > > do the same from Pojos hand made for unit test, it > work. > > > > I don't know what really happen, but i'm sure > that it is an equality test > > falling 'cause of the hibernate proxys. > > > > I don't get also any kind of error or exception, > since it ALL WORK. Just > > the rule isn't be acomplished. > > > > I'm using EJB3 + JPA (hibernate provider) and > Drools 4 GA; > > > > thanks in advance for any help > > > > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Hibernate proxy objects equality tests failing in Drools 5
on this afternoon I will migrate to Drools 5 CR1, unfortunelly i'm not sure if it will solve my problem. Does anyone else uses Drools with objects that came from an hibernate, (proxies)? Also, i'm not using any proxy to fetch lazy data inside my Drools stateful session. thanks Guto escreveu: > I was following that subject on markmail, and them I've enterred the > user-group (so subject and body are coppied from them). I've got the > exactly same problem. When I use the rules with objects the came from the > database (thru JPA hibernate provider), thouse rules never match. When I > do the same from Pojos hand made for unit test, it work. > > I don't know what really happen, but i'm sure that it is an equality test > falling 'cause of the hibernate proxys. > > I don't get also any kind of error or exception, since it ALL WORK. Just > the rule isn't be acomplished. > > I'm using EJB3 + JPA (hibernate provider) and Drools 4 GA; > > thanks in advance for any help > ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Hibernate proxy objects equality tests failing in Drools 5
I was following that subject on markmail, and them I've enterred the user-group (so subject and body are coppied from them). I've got the exactly same problem. When I use the rules with objects the came from the database (thru JPA hibernate provider), thouse rules never match. When I do the same from Pojos hand made for unit test, it work. I don't know what really happen, but i'm sure that it is an equality test falling 'cause of the hibernate proxys. I don't get also any kind of error or exception, since it ALL WORK. Just the rule isn't be acomplished. I'm using EJB3 + JPA (hibernate provider) and Drools 4 GA; thanks in advance for any help -- Guto Maia CSM - SCJP- SCWCD - SCBCD - ZCE Chris, When you use "==" in a DRL field constraint (not eval), drools always translates it into an .equals() call. Having said that, there might be other problems, since drools must rely on object identity for some internal data structures... for instance, we use IdentityMaps for mapping FactHandles and the actual fact objects, etc. We would need to test this and see what can be done. Could you please open a JIRA and attach a test case so that we can reproduce the problem? Thanks, Edson 2009/4/26 CK Hi, I'm testing out some simple codes using Hibernate and Drools 5 and I'm hitting an issue with hibernate proxy objects. With the newer version of hibernate, Javassist is used to proxy some hibernate objects. By doing this, hibernate objects essentially cannot use == comparisons, which is fine. However, this is causing issue in equality checks within Drools 5 LHS evaluations of hibernate persistent objects. Let's say for example I have the following Hibernate objects: class Parent { Child child; } class Child { String name; } normally, if you output Parent.child, it should be Child.class. But under Hibernate, the child property in Parent may be proxied and enhanced with Javassist, thus making Parent.child.class to be something like "Child_$$_javassist_75". Inside Drools, in the LHS: when $child : Child() $parent : Parent(child == $child) then ... end Assume that I have insert separate Child instances here that were retrieved from an Hibernate query directly. Assume that I have also inserted Parent instances that were retrieved from a separate query without eager fetching. Given this particular case, the above rule would not match even though it technically should. Under normal java code, using equality, the parent's child is equal to the child. According to MVEL language, which Drools LHS may not necessarily be using, equality between two objects are compared using values. Not sure exactly what that means. Either way, this seems to be a rather unfortunate problem for using Drools to work with Hibernate objects. Older hibernate versions didn't cause this problem. It seemed like jBPM had a similar problem according to the following doc: http://www.jboss.org/community/docs/DOC-11169 Excerpt: Object identity and object equality MAKE SURE TO USE ALWAYS .equals AND NEVER == comparisons in the Java code. Typically, in the PVM Java objects, we want to use the default object identity as the object equality. But hibernate persistence breaks this (even within the scope of one hibernate session) because of the proxies. So we have to apply a trick in order to make the comparison between a persistent object and its proxy return true. See jBPM 3 class EqualsUtil for that trick. So my question is whether Drools uses equality or identity when it comes to comparing values in LHS constraints. Is there a way to get around this issue? -Chris ___ rules-users mailing list rule...@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users -- Edson Tirelli JBoss Drools Core Development JBoss, a division of Red Hat @ www.jboss.com ___ rules-users mailing list rule...@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Hibernate proxy objects equality tests failing in Drools 5
Chris, When you use "==" in a DRL field constraint (not eval), drools always translates it into an .equals() call. Having said that, there might be other problems, since drools must rely on object identity for some internal data structures... for instance, we use IdentityMaps for mapping FactHandles and the actual fact objects, etc. We would need to test this and see what can be done. Could you please open a JIRA and attach a test case so that we can reproduce the problem? Thanks, Edson 2009/4/26 CK > Hi, > > I'm testing out some simple codes using Hibernate and Drools 5 and I'm > hitting an issue with hibernate proxy objects. > > With the newer version of hibernate, Javassist is used to proxy some > hibernate objects. By doing this, hibernate objects essentially cannot use > == comparisons, which is fine. > > However, this is causing issue in equality checks within Drools 5 LHS > evaluations of hibernate persistent objects. > > Let's say for example I have the following Hibernate objects: > > class Parent { >Child child; > } > > class Child { >String name; > } > > normally, if you output Parent.child, it should be Child.class. But under > Hibernate, the child property in Parent may be proxied and enhanced with > Javassist, thus making Parent.child.class to be something like > "Child_$$_javassist_75". > > Inside Drools, in the LHS: > > when > $child : Child() > $parent : Parent(child == $child) > then > ... > end > > Assume that I have insert separate Child instances here that were retrieved > from an Hibernate query directly. Assume that I have also inserted Parent > instances that were retrieved from a separate query without eager fetching. > Given this particular case, the above rule would not match even though it > technically should. Under normal java code, using equality, the parent's > child is equal to the child. > > According to MVEL language, which Drools LHS may not necessarily be using, > equality between two objects are compared using values. Not sure exactly > what that means. > > Either way, this seems to be a rather unfortunate problem for using Drools > to work with Hibernate objects. Older hibernate versions didn't cause this > problem. > > It seemed like jBPM had a similar problem according to the following doc: > > http://www.jboss.org/community/docs/DOC-11169 > > Excerpt: > > Object identity and object equality > > MAKE SURE TO USE ALWAYS .equals AND NEVER == comparisons in the Java code. > > Typically, in the PVM Java objects, we want to use the default object > identity as the object equality. But hibernate persistence breaks this > (even within the scope of one hibernate session) because of the proxies. So > we have to apply a trick in order to make the comparison between a > persistent object and its proxy return true. See jBPM 3 class EqualsUtil > for that trick. > > > > So my question is whether Drools uses equality or identity when it comes to > comparing values in LHS constraints. Is there a way to get around this > issue? > > -Chris > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users > -- Edson Tirelli JBoss Drools Core Development JBoss, a division of Red Hat @ www.jboss.com ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Hibernate proxy objects equality tests failing in Drools 5
Hi, I'm testing out some simple codes using Hibernate and Drools 5 and I'm hitting an issue with hibernate proxy objects. With the newer version of hibernate, Javassist is used to proxy some hibernate objects. By doing this, hibernate objects essentially cannot use == comparisons, which is fine. However, this is causing issue in equality checks within Drools 5 LHS evaluations of hibernate persistent objects. Let's say for example I have the following Hibernate objects: class Parent { Child child; } class Child { String name; } normally, if you output Parent.child, it should be Child.class. But under Hibernate, the child property in Parent may be proxied and enhanced with Javassist, thus making Parent.child.class to be something like "Child_$$_javassist_75". Inside Drools, in the LHS: when $child : Child() $parent : Parent(child == $child) then ... end Assume that I have insert separate Child instances here that were retrieved from an Hibernate query directly. Assume that I have also inserted Parent instances that were retrieved from a separate query without eager fetching. Given this particular case, the above rule would not match even though it technically should. Under normal java code, using equality, the parent's child is equal to the child. According to MVEL language, which Drools LHS may not necessarily be using, equality between two objects are compared using values. Not sure exactly what that means. Either way, this seems to be a rather unfortunate problem for using Drools to work with Hibernate objects. Older hibernate versions didn't cause this problem. It seemed like jBPM had a similar problem according to the following doc: http://www.jboss.org/community/docs/DOC-11169 Excerpt: Object identity and object equality MAKE SURE TO USE ALWAYS .equals AND NEVER == comparisons in the Java code. Typically, in the PVM Java objects, we want to use the default object identity as the object equality. But hibernate persistence breaks this (even within the scope of one hibernate session) because of the proxies. So we have to apply a trick in order to make the comparison between a persistent object and its proxy return true. See jBPM 3 class EqualsUtil for that trick. So my question is whether Drools uses equality or identity when it comes to comparing values in LHS constraints. Is there a way to get around this issue? -Chris ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users