1 2 Previous Next 21 Replies Latest reply on May 30, 2004 5:47 AM by hbaxmann Go to original post
      • 15. Re: Nulls in CMR where clause
        hbaxmann

        I apologize.

        Let's bring this social NPE to an end:

        I apologize too for sounding anything else than helping. I neither know what "revendicative" in German is [babelfish and dict.leo.org doesn't help here] nor does I know _how_ to write or say something that it is sounding condescending in english - in German, you could be very, very sure, i’ll know. I want never ever accusing people - IMNSHO I accusing the design of RDBMSes, because I, like many other out here, make money with healing this sucking designs by implementing J2EE Apps on top of it, instead of repair this crap - but it is definitely no fun. And even I will have fun with my day-to-day work, seriously.

        So at last I have to apologize to not be an native english speaker. Nice. And, yes, here I am still a newbeee. As shown. My fault.

        OTOH it makes me wondering, that at most young people are afraid of beeing criticised. Often there is no understanding for the difference of saying: "Your ER model sucks" and "You sucks". How less could one stand on his own if he feels attacked if one attacks his ER model? And how arrogant and ignorant ?

        Ok, let's take this case straight:

        Precondition:

        We have one table in a relational DB with four colums:

        ID Name City Street Zip

        ID is the PK
        Name is a NOT NULL column
        City is a nullable column
        Street is a nullable column
        Zip is a nullable column

        I understand the problem as follows:

        ID Name City Street Zip
        1 Miller Frisco
        2 Frank Way 10000
        3 Paul Frisco 10000
        4 Smith Ave.

        Simple case Query: Give me all Name, where the Zip is 10000 (Zip is $1) or Zip is not existing ($1 is null)

        This is a self-outer-join on the table.

        EJBQL: SELECT DISTINCT OBJECT(t) FROM TheTable t WHERE t.Zip IS NULL OR t.Zip =?1

        The “table.col = ?1 OR (table.col IS NULL AND null=?1)” does not work, because there will occur a short-circuit to “table.col = ?1“, because of ‘NULL=anything’ is always false.

        The “business key” - a concept which does not exist on DB level - consists now on City, Street and Zip. The query should deliver all three columns, regardless if they are NULL or not.

        Right so far ?

        Problem Query: Give me all Name where Zip is 10000 or not existent and give me all Name where City is Frisco or not existent.

        So expected result should show:

        Name
        Miller
        Frank
        Paul

        What I would suggest in this case is to build a Frisco_view and Zip10000_view:

        Beforehand: This is a workaround for not changing the underlying DB-model, otherwise there should be a ID_CityTable and a ID_ZipTable - there should than performed outer joins with the TheTable, but this is DB and DB-version (oracle I know here) dependend, because the outer joins (left, right, full) are implemented differently in syntax and function by the vendors.

        Now the ugly workaround:

        Create View Frisco_view as
        Select ID, City from TheTable where City=Frisco or City IS NULL;

        Create View Zip10000_view as
        Select ID, Zip from TheTable where Zip=10000 or Zip IS NULL;

        Create View MultipleSelfOuterJoin_Frisco_10000_Query as
        Select tt.ID, tt.Name, zv.Zip, fv.City from
        TheTable tt, Frisco_view fv, Zip10000_view zv where
        (tt.ID = fv.ID) and (tt.ID = zv) and (fv.ID = zv.ID)

        Select Name from MultipleSelfOuterJoin_Frisco_10000_Query;

        Depending on the RDBMS, it might happen that the views beeing materialized by the optimizer.

        ... and, yes, there have DDL statements dynamically, at runtime, to be performed. It is a workaround.

        Ref: Joe Celko’s SQL Puzzles & Answers, Morgan Kaufmann 1997, ISBN1-55860-453-7; Puzzle 14: Telephone

        BTW: the Subject itself is a oxymoron: CMR should provide results where something is existent _and_ not existent according to SQL. Most OR tools are struggling with this structural weakness of the relational world.

        bax

        • 16. Re: Nulls in CMR where clause
          ironbird

          revendicative means "claiming your truth at the expense of those of others"
          This forum is for helping each other to make everyone find its truth (means the way where its application works). Blaming J2EE, JBoss, ER designers or ER models got nothing to do with this forum.
          So, finallly, make a choice between a DynamicSQL statement or adding views, or whatever belongs to Erik.
          Nothing we can do more than that.

          • 17. Re: Nulls in CMR where clause
            hbaxmann

            Thanks.

            Then I apologize for sounding revendicative. Never want to draw upon the objective truth, know that this is not existing. My truth is simply my truth, not more - but not less.

            bax

            • 18. Re: Nulls in CMR where clause
              erik777

              hbaxmann:

              Thank you for posting the message with kinder English and approaching it technically without commenting on a person's skill levels. I apologize if I was harsh on your choice of words, or use of English.

              I'll respond to the technical notions in your post now as best I can.

              EJBQL: SELECT DISTINCT OBJECT(t) FROM TheTable t WHERE t.Zip IS NULL OR t.Zip =?1

              The ?table.col = ?1 OR (table.col IS NULL AND null=?1)? does not work, because there will occur a short-circuit to ?table.col = ?1?, because of ?NULL=anything? is always false.


              The problem with that EBJ-QL query isn't that ?NULL=anything? is always false, but that it will return all nulls (t.Zip IS NULL OR ...) even when ?1 isn't null. What would be ideal is:

              EJBQL: SELECT DISTINCT OBJECT(t) FROM TheTable t
               WHERE (t.Zip IS NULL AND ?1 IS NULL) OR t.Zip =?1
              


              but ?1 IS NULL is not an option in EJB-QL today. The problem currently with EJB-QL is that you cannot test if the parameter itself is null.

              The original question I had is when will it or an equivilant be an option, since testing for null parameters has never been an issue with SQL development before? Although EJB-QL chose to adhere largely to SQL syntax, I think that to solve the problem where it is clearly deficient in contrast to SQL, and particularly dynamic SQL where you combine code logic with resulting SQL output, it could improve by doing things differently. In Java, variable=null does return true if the variable is null. Why not permit it in EJB-QL?

              The requirements for this entity are:

              - Reusable by all applications
              - Works with all database vendors
              - Works with all J2EE vendors
              - Very high performance
              - Extremely simple

              Views are ruled out for two reasons. One, they are an unacceptable hit on performance. Two, they are not supported by all database vendors.

              Now, let's say that views were acceptable. Using your example, 16 views would be necessary in this case. The reality is there are 4 optional columns in the business key. Any of them can be null. The keys are not related to each other. Any conceptual relationships that might occur inthe applications is arbitrary. Using the samle you posted, meaning that views didn't have unions, you would have to have 16 individual views just for this one query to handle every possible combination of null / not-null values.

              Contrast this to my current solution of using dummy null values. It's working today. It doesn't have the high performance cost of views, and works with all database vendors. It is seemless to the applications, since they can still use nulls, and will still get back nulls, never knowing that a dummy null value was substituted.

              Thus, this entity became one of a growing list of examples since EJB-QL came out of problems with nulls in the queries. But, using views clearly are not in line with the requirements. The question I originally asked is what was the progress of JBoss or J2EE on this issue? The question was partially answered when someone said you could do it today with DynamicSQL. That last time I check, DynamicSQL couldn't do it, ironbird essentially answered my question as to where JBoss has progressed on it today. The only question I still have is where is J2EE and the JSR's on this?

              Thank you hbaxmann for helping. Your proposal to use views to denormalize certain can work and has merit. It's just not the option for the problem I have.

              And thank you ironbird for the DynamicSQL info. Although this entity needs to work with all J2EE vendors since it's in a foundation class library, I'll probably use DynamicSQL until a JSR fixees this for entities that can afford some vendor dependency. Happy JBoss development!



              • 19. Re: Nulls in CMR where clause
                hbaxmann

                Thanks for your kind reply :)))

                Mhhhm, i do not see an end here either.

                The Java vs. DB NULL problem is an chicken-and-egg problem. The NULL in the DB is not the Java NULL, so it must be converted in both directions. That for you have to test if it is NULL. Circle closed.

                Do you have the full control over the Table and Relation layout?
                If you provide more detailed information about what you are modeling, I am sure there is a way like the address splitting approach. Not the one-size-fits-it-all, but here we have a special case, which should be solved in a general manner. Have done it the last 25 years ;-)

                bax

                • 20. Re: Nulls in CMR where clause
                  erik777

                  Thanks, hbaxmann, for the offer to further analyze the issue. Since the issue is resolved, I consider its relevance reduced to being an example of the greater problem. I'd love to spend time using examples to go over the theoretical possibilities, but really do have a lot on my plate today.

                  For those following this, the current status on the JSR follows.

                  JSR 220 (http://jcp.org/en/jsr/detail?id=220) is developing EJB 3.0, which includes improvements to EJB-QL. The JSR is scheduled to release either an EARLY or PUBLIC DRAFT in June 2004, so will hopefully be releasing it soon. Due to the confidentiallity agreemant JCP members sign (JSPA para 9), any current discussions and draft copy is "hush hush" until they officially release an EARLY or PUBLIC DRAFT.

                  Although this spec promises to focus on usability and productivity of developers, the spec description does say it is not limitted to that, and even appears to emphasize the need to improve EJB-QL:

                  "Enhancements to container-managed persistence and EJB QL to provide greater usability and to facilitate the development of frameworks based on container-managed persistence."


                  I believe their creation of the early draft could use even more public transparancy than JCP 2.6 provides (http://jcp.org/en/procedures/jcp2).

                  Since JSR 220 was started with JCP 2.5, its not clear if an EARLY DRAFT was already completed that might have been public if it began under 2.6. It's under 2.6 now, which is fairly new (http://java.sun.com/developer/technicalArticles/jcp26/). Yet, I think for important JSRs like this one, even JCP 2.6 is too restrictive since the non-member public at-large cannot review or discuss drafts until they are stamped ready for public review. This is why you don't see anyone from JBoss posting on this thread.

                  Let's hope we can publicly discuss it in June.



                  • 21. Re: Nulls in CMR where clause
                    hbaxmann

                    Uhu. Aha.

                    bax

                    1 2 Previous Next