[Mdarad-toolbox-devs] =?ISO-8859-1?Q?=EFch=2C_Weirdest_Persistance_Bug_Ever?=
                
                Brought to you by:
                
                    erifr
                    
                
            
            
        
        
        
    | 
     
      
      
      From: Vincent-Olivier A. <vi...@up...> - 2006-02-08 11:45:38
      
     
   | 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> </head> <body bgcolor="#ffffff" text="#000000"> Hi Guys,<br> <br> I found the ugliest, weirdest persistance bug ever, I think. Ok. It happens in the context of a one-to-one composition that is navigable in both ways.<br> <br> Example, take the Motion concept (a proposal at a company's shareholder meeting). Sometimes, you need to attach to a Motion instance, a MotionAnalysis. So there is a one-to-one composition from Motion to MotionAnalysis called "analysis<-->motion", that is navigable in both ways.<br> <br> Ok, I admit that it might not be the very best model pattern, but hey, sometimes the model grows hairy without some of the hairiness being noticed.<br> <br> So first, anyways when you have this, first, in the SQL table structure, you have a, in the MOTION table, a MOTION_ANALYSIS_FK <b>and</b>, in the MOTION_ANALYSIS table, you also get a MOTION_FK. When, of course, only one of the foreign key reference is necessary. This is the first part of the bug.<br> <br> Also, when you create a MotionAnalysis insance from the a Motion instance, Hibernate sets the MOTION.MOTION_ANALYSIS_FK field, but leaves the MOTION_ANALYSIS.MOTION_FK in a null state. This seems to explain the following behavior, which is the visible tip of the bug... When you retrieve an instance from the MotionAnalysis "side"  :<br> <pre>FROM MotionAnalysis AS ma WHERE ma.published <= current_date() AND ma.published >= :startDate ORDER BY ma.published DESC </pre> the MotionAnalysis.motion is always null (ma.motion is null), which is impossible because it is a composition.<br> <br> But, when you get it from the Motion "side" : <br> <pre>FROM Motion AS mo JOIN mo.analysis AS ma WHERE ma.id IS NOT null AND ma.published <= current_date() AND ma.published >= :startDate AND mo.meeting.enterprise.country.id IN (SELECT country.id FROM Client client INNER JOIN client.analysisCountries AS country WHERE client.id = :clientId) ORDER BY ma.published DESC </pre> , everything is fine... That is, the association is set correctly, etc. The worst thing is that this was working only some weeks ago, as I tested it myself...<br> <br> <br> Vincent<br> </body> </html>  |