Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » JPA Query generate uppercase field names
JPA Query generate uppercase field names [message #376349] Tue, 15 July 2008 18:50 Go to next message
Glenn is currently offline GlennFriend
Messages: 14
Registered: July 2009
Junior Member
I have a query, select b from Button b, that generates the following SQL:
SELECT BTNID, BTN1NAME, BTN2NAME FROM errorMsgBtnList.

My Button entity is as follows:

@Entity
@Table(name="errorMsgBtnList")
public class Button {

@Id
private int btnId;
private String btn1Name;
private String btn2Name;

public Button(){

}

public String toString(){
return "Button(" + btn1Name + " " + btn2Name + ")";
}

}

My database table has column names btnId, btn1Name and btn2Name, so the
query generates the following error:

Internal Exception: com.sybase.jdbc3.jdbc.SybSQLException: Invalid column
name 'BTN2NAME'.

Is there an eclipselink property I can set in persistence.xml to eliminate
this error? If not, how else can I eliminate case-sensitivity from queries
in EclipseLink?
Re: JPA Query generate uppercase field names [message #376353 is a reply to message #376349] Wed, 16 July 2008 13:10 Go to previous messageGo to next message
James is currently offline JamesFriend
Messages: 272
Registered: July 2009
Senior Member
Uppercase field names are the default for JPA. You can override the
default column name using the @Column annotation.

Alternatively you could probably make a DescriptorCustomizer or
SessionCustomizer that iterates over the EclipseLink ClassDescriptor's
DatabaseMappings and changes their field names to lower case.

You could also change your schema to be upper case.

-- James
Re: JPA Query generate uppercase field names [message #376356 is a reply to message #376353] Wed, 16 July 2008 19:44 Go to previous messageGo to next message
Brian Vosburgh is currently offline Brian VosburghFriend
Messages: 137
Registered: July 2009
Senior Member
James wrote:

> Uppercase field names are the default for JPA.

Where is that stated? :-)
Re: JPA Query generate uppercase field names [message #376357 is a reply to message #376356] Wed, 16 July 2008 20:16 Go to previous messageGo to next message
Glenn is currently offline GlennFriend
Messages: 14
Registered: July 2009
Junior Member
Brian makes a good point.

I never had this problem with Hibernate.
And, since I can't change my database schema to all uppercase,
that leaves me to annotate every field in my entities with
@Column(name="..."). That's a lot of unnecessary work, if you
ask me. And it make a mockery of the notion that JPA is
configuration by exception.

Glenn...
Re: JPA Query generate uppercase field names [message #376365 is a reply to message #376356] Thu, 17 July 2008 13:02 Go to previous messageGo to next message
Gordon Yorke is currently offline Gordon YorkeFriend
Messages: 78
Registered: July 2009
Member
Sections 2.1.X . The specification requires uppercase names for defaulted
database object names.

We could however, easily add a flag to process the attribute names as-is.

Glen please file an enhancement request.
--Gordon
Re: JPA Query generate uppercase field names [message #376366 is a reply to message #376365] Thu, 17 July 2008 14:35 Go to previous messageGo to next message
Brian Vosburgh is currently offline Brian VosburghFriend
Messages: 137
Registered: July 2009
Senior Member
Gordon Yorke wrote:
> Sections 2.1.X . The specification requires uppercase names for
> defaulted database object names.

Hmmm. I can't find that requirement. What page? Thanks, Gordon.

Brian
Re: JPA Query generate uppercase field names [message #376367 is a reply to message #376366] Thu, 17 July 2008 14:53 Go to previous messageGo to next message
Gordon Yorke is currently offline Gordon YorkeFriend
Messages: 78
Registered: July 2009
Member
It is throughout the rules for default naming. Look at page 26-27 for
foreign key column names. There's an example on page 35 the shows the
defaults for non-relationship column names. It is very clear throughout
these sections that the specification intends for default column names to
be an upper case version of the property name.
--Gordon
Re: JPA Query generate uppercase field names [message #376368 is a reply to message #376367] Thu, 17 July 2008 15:41 Go to previous message
Brian Vosburgh is currently offline Brian VosburghFriend
Messages: 137
Registered: July 2009
Senior Member
Gordon Yorke wrote:
> It is throughout the rules for default naming. Look at page 26-27 for
> foreign key column names. There's an example on page 35 the shows the
> defaults for non-relationship column names. It is very clear throughout
> these sections that the specification intends for default column names
> to be an upper case version of the property name.
> --Gordon
>

I disagree that "it is very clear". If it were "clear", it would be
unequivocably stated in the text of the spec. When I asked co-spec lead
Mike Keith for clarification of this issue, he said "the spec does not
address it". The use of uppercase in any particular example is because
that is the actual name of the particular database object in that example.
The use of uppercase also makes it easier for the reader to discern when
the example is referring to a database identifier and when it is referring
to a database identifier.

Folding to uppercase *is* a typical way of handling undelimited identifiers
(in fact the SQL standard demands it); but, by default, numerous popular
databases do NOT fold to uppercase (and violate the SQL spec). PostgreSQL,
Informix, and (sometimes) MySQL fold to lowercase; while Microsoft and Sybase
do not fold at all.

As counterpoints in the spec, the "default" Entity name is NOT folded to
uppercase; and the none of the descriptions of the annotations mention
anything about folding the defaults to uppercase. For example, the table
on page 164 says the default for Table.name is "Entity name", not "Entity
name folded to uppercase". Does not the the "Entity name" have the same
case as the Java identifier? Likewise the table on page 167 says the
default for Column.name is "The property or field name" - nothing about
folding to uppercase.

Sorry about the excess of details, but I'm in the middle of handling
case-sensitivity issues in Dali. :) In Dali we will likely be using the
identifiers unmodified and allowing for a setting that allows us to ignore
case. Sort of the opposite of your earlier suggestion for an EclipseLink
setting. Needless to say, the issue is difficult.

Brian
Previous Topic:Problem with persistence cache using JPA
Next Topic:How can I use Hibernate, or OpenJPA with EclipseLink
Goto Forum:
  


Current Time: Thu Apr 18 07:48:32 GMT 2024

Powered by FUDForum. Page generated in 0.02333 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top