Re: Problems with Hibernate Discriminators and 9.0-801.jdbc4

From: Chris Wareham <cwareham(at)visitlondon(dot)com>
To: "Lew" <noone(at)lewscanon(dot)com>
Cc: <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Problems with Hibernate Discriminators and 9.0-801.jdbc4
Date: 2011-03-28 14:38:09
Message-ID: 4D909D51.3020104@visitlondon.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On 03/28/11 14:27, Lew wrote:
> Chris Wareham wrote:
>> Dave Cramer wrote:
>>> Ok, looking at the hibernate source this is what is in the PostgreSQLDialect
>>>
>>> public String getIdentitySelectString(String table, String column, int type) {
>>> return new StringBuffer().append("select currval('")
>>> .append(table)
>>> .append('_')
>>> .append(column)
>>> .append("_seq')")
>>> .toString();
>>> }
>>> }
>
>> Just as an aside, should that not be using a StringBuilder rather than
>> a StringBuffer? Or does Hibernate still explicitly support Java 1.4?
>
> My Red-Flag-O-Meter triggered on that, too. What Hibernate ought to do is:
>
> return "select currval('" + table + '_' + column + "_seq')";
>
> for Pete's sake.
>
> I'm off to check if EclipseLink or OpenJPA is better written.
>

I was flagging this up due to StringBuffer's locking, despite it being
used in a local scope - in other words, it doesn't need to be thread
safe, so the locking overhead can be avoided by using a StringBuilder
instead. As I suggested, perhaps Hibernate still supports Java 1.4, or
wasn't rototilled for this kind of thing when 1.4 support was dropped.
If it's still a common idiom across the Hibernate codebase then it
would be nice to see it changed.

You're right that in this case concatenation will achieve the same
thing as using an explicit StringBuilder, at least in Java 1.6[1].

Chris

[1] http://kaioa.com/node/59
--


Chris Wareham
Senior Software Engineer
Visit London Ltd
6th floor,
2 More London Riverside
London SE1 2RR

Tel: +44 (0)20 7234 5848
Fax: +44 (0)20 7234 5753

http://www.visitlondon.com/


'Visit London Limited' is registered in England under No.761149;
Registered Office: Visit London, 2 More London Riverside, London SE1 2RR.

Visit London is the official visitor organisation for London. Visit London is partly funded by Partnership, the Mayor's London Development Agency and London Councils.
The information contained in this e-mail is confidential and intended for the named recipient(s) only. If you have received it in error, please notify the sender immediately and then delete the message. If you are not the intended recipient, you must not use, disclose, copy or distribute this email. The views expressed in this e-mail are those of the individual and not of Visit London. We reserve the right to read and monitor any email or attachment entering or leaving our systems without prior notice.

Please don't print this e-mail unless you really need to.

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Dave Cramer 2011-03-28 15:06:06 Re: Problems with Hibernate Discriminators and 9.0-801.jdbc4
Previous Message Віталій Тимчишин 2011-03-28 14:31:19 Re: Problems with Hibernate Discriminators and 9.0-801.jdbc4