Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id C6341632D98 for ; Fri, 23 Jul 2010 09:55:26 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 28289-07 for ; Fri, 23 Jul 2010 12:55:18 +0000 (UTC) Received: from news.hub.org (news.hub.org [200.46.204.72]) by mail.postgresql.org (Postfix) with ESMTP id A2F14632889 for ; Fri, 23 Jul 2010 09:55:19 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.14.4/8.14.4) with ESMTP id o6NCtB3s014388 for ; Fri, 23 Jul 2010 09:55:11 -0300 (ADT) (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.14.4/8.14.4/Submit) id o6NCltJl095350 for pgsql-jdbc@postgresql.org; Fri, 23 Jul 2010 09:47:55 -0300 (ADT) (envelope-from news) From: Lew X-Newsgroups: pgsql.interfaces.jdbc Subject: Re: JPA and desktop apps Date: Fri, 23 Jul 2010 08:48:18 -0400 Organization: albasani.net Lines: 35 Message-ID: References: <4C47B5F7.4050303@postnewspapers.com.au> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@albasani.net X-User-ID: yYHsMqMNS08SHvm/zO/pwHnAOMUflUFMfKJXEsGNNWY= In-Reply-To: <4C47B5F7.4050303@postnewspapers.com.au> Cancel-Lock: sha1:JRj1q/bgVvx4ObOas8VukrMCGGQ= User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.10) Gecko/20100528 Thunderbird/3.0.5 X-NNTP-Posting-Host: FeZYIdQjVeckzBTgVYb18UrKGslR1T+Fgq6ywIBSwo4= To: pgsql-jdbc@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.79 tagged_above=-10 required=5 tests=BAYES_50=0.8, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201007/88 X-Sequence-Number: 20753 Craig Ringer wrote: > Ages ago, I asked here if others were using JDBC directly to access Pg > from their java apps, or if they were using an ORM. I sought advice. > Many suggested that an ORM was a strongly preferable option, and partly > as a result of that advice I ended up using the JPA interface (with > Hibernate powering it) for my database access in my Swing app. > > I've now concluded that, while it seems great on the surface, that > approach is absolutely awful, because of issues with detatched entities, > lazy property fetching, and the need to run database work on a non-EDT > thread to avoid UI stalls/freezes and repaint delays. I don't find JPA a problem at all - it's a huge boost. Naturally you have to deal with properly setting it up, just like anything else. If lazy fetching is bad for you, use eager fetching. Simple. You need to run DB work on a non-GUI thread if you don't use an ORM. How is that different? Detached entities are part of a solution, not part of a problem. > Anyway, since folks here advised me to go for an ORM like Hibernate, I'm > curious: How do you handle the need to avoid blocking on database access > in your Java GUI apps, while lazily fetching properties of entities to > avoid downloading half the database whenever you query it for anything? Proper design of entities to fit with a proper object model. Proper separation of view from model, just like if you don't use an ORM. Methinks you blame the hammer for the carpenter. -- Lew