My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions
Issue 35: SQL error when using an enum
1 person starred this issue and may be notified of changes. Back to list
Status:  Fixed
Owner:  eric.bot...@gmail.com
Closed:  Feb 2009


 
Reported by yont...@gmail.com, Jan 6, 2009
I wanted to add a conditionnal expression with an enum.
I had something like :
ConditionalExpression  ce = eq(myObject.getEnumValue(), EnumValue.VALUE);
It produces the JPA code :
  myObject.enumValue = VALUE
When the JPA query is translated in SQL, the query is not valid with the
database schema. I tried to do something :
ConditionalExpression  ce = eq(myObject.getEnumValue(),
EnumValue.VALUE.name());
But it did not compile, because of the generics. So I download the sources
of the project and I add :
	else if (what.getClass().isEnum()) {
		return escape(what.toString());
	}
It produces :   myObject.enumValue = 'VALUE'
In my case, it was what I wanted because of the JPA annotation
'@Enumerated(EnumType.STRING)'. It would be better to support the fact that
if it was '@Enumerated(EnumType.ORDINAL)', it should produce the correct value.

PS: Sorry for this long issue :)
Jan 15, 2009
Project Member #1 eric.bot...@gmail.com
I think there is indeed a problem in LF code, but there may be a better solution.

IIRC, the spec says that the enum values should be fully qualified (ie 
com.company.MyEnum.MYVALUE in your case), which may explain why it didn't work.

You shouldn't have to bother about whether it's an ordinal or a String 
representation yourself (that's your JPA engine job).

so what i'm saying is that instead of escape(what.toString()); you could try to just 
return the fullty qualified name of the value.

HTH, I will look at it asap.


Jan 15, 2009
Project Member #2 eric.bot...@gmail.com
(No comment was entered for this change.)
Labels: Milestone-Release1.0
Feb 13, 2009
Project Member #3 eric.bot...@gmail.com
Fixed in r110
Status: Fixed
Owner: eric.bottard

Powered by Google Project Hosting