Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 86348 invoked from network); 17 May 2007 14:55:34 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 17 May 2007 14:55:34 -0000 Received: (qmail 84089 invoked by uid 500); 17 May 2007 14:55:37 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 84077 invoked by uid 500); 17 May 2007 14:55:37 -0000 Mailing-List: contact user-java-help@ibatis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user-java@ibatis.apache.org Delivered-To: mailing list user-java@ibatis.apache.org Received: (qmail 84066 invoked by uid 99); 17 May 2007 14:55:36 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 May 2007 07:55:36 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Received: from [196.35.77.149] (HELO mfwjhe02.mfw.is.co.za) (196.35.77.149) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 May 2007 07:55:27 -0700 Received: from as-smtp04.he.businessgateway.co.za (Not Verified[196.26.57.70]) by mfwjhe02.mfw.is.co.za with MailMarshal (v6,1,8,2172) id ; Thu, 17 May 2007 16:51:55 +0200 Received: from pascptwsmeind ([41.245.186.64]) by as-smtp04.he.businessgateway.co.za with Microsoft SMTPSVC(6.0.3790.1830); Thu, 17 May 2007 16:54:59 +0200 From: "Meindert" To: Subject: RE: Conditional joins? Date: Thu, 17 May 2007 16:54:59 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook, Build 11.0.5510 Thread-Index: AceYkK8QDEk0t5I4SiySN0kl52RWDgAAeGNA X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 In-Reply-To: <20070517143613.2E88014D82A@smtp-2.sys.kth.se> Message-ID: X-OriginalArrivalTime: 17 May 2007 14:54:59.0686 (UTC) FILETIME=[575FD060:01C79893] X-Virus-Checked: Checked by ClamAV on apache.org I'm doing it by checking the Foreign Key value and the use of If I don't want to join I set the Foreign Key value to null And in the statement SELECT .... {Fields from the joined table} FROM maintable JOIN ... Kind Regards Meindert -----Original Message----- From: Matthias Karlsson [mailto:mc@kth.se] Sent: 17 May 2007 04:36 PM To: user-java@ibatis.apache.org Subject: Conditional joins? Hi, I'm currently evaluating frameworks for writing DAO layers for future projects, replacing a custom one I previously wrote. The current one works well, but it needs much more work. Long story short, it relies on being able to retrieve values using table aliases in the ResultSet::getXXX-methods, which works with MySQL but not (for example) with PostgreSQL. Anyway, I'm currently looking into Hibernate and iBatis (and possibly working on our custom...). Hibernate seems advanced enough, but I think its "black box" is a little too big for me. Furthermore, I like SQL and would very much prefer to be able to continue to use it, which was what made me find iBatis to begin with. Browsing through your documentation it seems to be able to do pretty much the only thing I want: write SQL and have it mapped to beans in a way I see fit. Hibernate seems to think that the Java model should dictate the structure of the database, which I do not agree with. The database is the most important model you have, and I would much rather have it properly structured, even if it means the Java model is far from optimal (from a OOP point-of-view). Anyway, to get to the point, one of the reasons for me writing a custom framework to begin with was that we (felt that we) really needed to have as much control as possible as a user of the framework when it came to joins and such. As a result, a user of the framework, when querying for an object A mapped to a table T (our objects are always fully mapped to tables) is able to specify in the method being called what should be joined in the query. For example, let's say there are foreign keys in T to U and V, mapped to objects B and C respectively. If a user of the framework knows that he will need B and C along with A, he can say so and they will be joined and automatically fetched in one query. If not, just A can be queried for and if B and C would be needed at the later stage anyway, they can be fetched explicitly (though then of course with additional queries). I liked the -tag when I read about it, but is there any support for conditional joins (e.g., if parameter hash h contains value v, join this table) or would you need to handle the different cases explicitly by creating different queries (possibly using fragments to cut down on the copied code)?. I understand that this is very special case and I'm probably trying to solve a problem that isn't even worth thinking about. It's just that I come from a background where every query counts so I was forced to be able to handle all these cases. Any feedback would be much appreciated. Sincerely, Matthias