Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!news.swapon.de!aioe.org!.POSTED!not-for-mail From: =?UTF-8?Q?Arne_Vajh=c3=b8j?= Newsgroups: comp.lang.java.programmer Subject: Re: From JDBC to JPA Date: Sat, 25 Jul 2015 23:49:00 -0400 Organization: Aioe.org NNTP Server Lines: 35 Message-ID: References: <87380doatw.fsf@Equus.decebal.nl> <87y4i5mig2.fsf@Equus.decebal.nl> NNTP-Posting-Host: bLmKSxgyEsD8qtT7wjgUDQ.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 X-Notice: Filtered by postfilter v. 0.8.2 X-Mozilla-News-Host: news://nntp.aioe.org Xref: csiph.com comp.lang.java.programmer:32144 On 7/25/2015 4:12 AM, Fredrik Jonson wrote: > In <87y4i5mig2.fsf@Equus.decebal.nl> Cecil Westerhof wrote: > >> I need to write clean JPA code, because it should be possible two switch >> from Hibernate to openJPA in a moments notice. > > That is a requirement that is not as easy to fulfill as is appears on first > sight. Especially for someone who does not have experience with JPA already. > > I think you'll find that each JPA implementation has its own set of quirks in > performance as well as in configuration. And since you're combining it with a > database, you'll have your database provider's quirks to consider too. > > A more reasonable goal is to use only standard JPA annotations for the beans > and most queries, and otherwise aim to limit the provider specific stuff to > parts of the code that you design to be rather easily replaceable when you > decide to try to migrate to another provider. That said, you can get quite far > with plain JPA, at least as long as your database model isn't too complex. > > Not to say that JPA is special in this way. Almost every standard that have > multiple implementations also have quirks that are specific to each > implementation. The common case is obviously usually better covered and more > similar between implementations. > > On a related theme: Do not be afraid to use native queries when building more > complex queries. There's nothing wrong with JQL, but you do not have the same > control over the details compared to plain SQL. It is my impression that a lot of people (maybe the large majority of people) are able to do with only standard JPA code - maybe with a small dose of standard SQL where necessary. Arne