[
https://jira.jboss.org/jira/browse/JBSEAM-4117?page=com.atlassian.jira.pl...
]
Julien Kronegg updated JBSEAM-4117:
-----------------------------------
Description:
Each EntityList generated by Seam-gen contains RESTRICTIONS like the following one:
"lower(myEntity.myField) like lower(concat(#{myEntityList.myEntity.myField},
'%'))"
While this works fine under Hibernate, other JPA providers may not support this syntax as
it is not described in the JPA specifications (1.0 and 2.0): the right hand side of the
"LIKE" term must be a String, not a function. For OpenJPA, this problem is
described in the following JIRA issue:
https://issues.apache.org/jira/browse/OPENJPA-920
Solution:
In order to make Seam-gen's entityLists supported by other JPA providers, we could add
a new Seam component JpaProviderUtils
@Name("jpaProviderUtils") {
public class JpaProviderUtils {
/**
* Returns the right hand side parameter of a like query (i.e. the X in
"someField LIKE X) from a given String parameter.
* The returned string all lower case and ends with a "%" wildcard, which
is an equivalent of Hibernate HQL expression "lower(concat(X, '%'))".
* Null is returned if the input parameter is null or empty. Note: if null is
returned, the LIKE query may be discarded by the JPA provider.
* @param likeParameter the like parameter to make lower case and wildcarded
* @return the lower case/wildcarded parameter; null is returned for null or empty
parameter
*/
public String getLikeParameter(String likeParameter) {
return (likeParameter!=null &&
likeParameter.length()>0?likeParameter.toLowerCase()+'%':null);
}
}
Then seam-gen must be modified to produce RESTRICTIONS such as:
"lower(myEntity.myField) like
#{jpaProviderUtils.getLikeParameter(myEntityList.myEntity.myField)}"
This is done simply by updating the seam-gen/src/EntityList.java.ftl (from Seam
2.1.2-SNAPSHOT):
-line 26 :
"lower(${componentName}.${property.name}.${componentProperty.name}) like
lower(concat(${'#'}{${listName}.${property.name}.${componentProperty.name}},
'%'))",
+line 26 :
"lower(${componentName}.${property.name}.${componentProperty.name}) like
${'#'}{jpaProviderUtils.getLikeParameter(${listName}.${property.name}.${componentProperty.name})}",
-line 31: "lower(${componentName}.${property.name}) like
lower(concat(${'#'}{${listName}.${property.name}}, '%'))",
+line 31: "lower(${componentName}.${property.name}) like
${'#'}{jpaProviderUtils.getLikeParameter(${listName}.${property.name})}",
was:
Each EntityList generated by Seam-gen contains RESTRICTIONS like the following one:
"lower(myEntity.myField) like lower(concat(#{myEntityList.myEntity.myField},
'%'))"
While this works fine under Hibernate, other JPA providers may not support this syntax as
it is not described in the JPA specifications (1.0 and 2.0): the right hand side of the
"LIKE" term must be a String, not a function. For OpenJPA, this problem is
described in the following JIRA issue:
https://issues.apache.org/jira/browse/OPENJPA-920
Solution:
In order to make Seam-gen's entityLists supported by other JPA providers, we could add
a new Seam component JpaProviderUtils
@Name("jpaProviderUtils") {
public class JpaProviderUtils {
public String getLikeParameter(String likeParameter) {
return (likeParameter!=null?likeParameter.toLowerCase()+'%':null);
}
}
Then seam-gen must be modified to produce RESTRICTIONS such as:
"lower(myEntity.myField) like
#{jpaProviderUtils.getLikeParameter(myEntityList.myEntity.myField)}"
This is done simply by updating the seam-gen/src/EntityList.java.ftl (from Seam
2.1.2-SNAPSHOT):
-line 26 :
"lower(${componentName}.${property.name}.${componentProperty.name}) like
lower(concat(${'#'}{${listName}.${property.name}.${componentProperty.name}},
'%'))",
+line 26 :
"lower(${componentName}.${property.name}.${componentProperty.name}) like
${'#'}{jpaProviderUtils.getLikeParameter(${listName}.${property.name}.${componentProperty.name})}",
-line 31: "lower(${componentName}.${property.name}) like
lower(concat(${'#'}{${listName}.${property.name}}, '%'))",
+line 31: "lower(${componentName}.${property.name}) like
${'#'}{jpaProviderUtils.getLikeParameter(${listName}.${property.name})}",
Seam-gen generate EntityList with RESTRICTIONS which do not work for
other JPA providers
----------------------------------------------------------------------------------------
Key: JBSEAM-4117
URL:
https://jira.jboss.org/jira/browse/JBSEAM-4117
Project: Seam
Issue Type: Bug
Components: Tools
Affects Versions: 2.0.0.GA, 2.1.1.GA, 2.1.2.CR1
Environment: OpenJPA 1.2.1, Seam 2.1.2-SNAPSHOT
Reporter: Julien Kronegg
Original Estimate: 4 hours
Remaining Estimate: 4 hours
Each EntityList generated by Seam-gen contains RESTRICTIONS like the following one:
"lower(myEntity.myField) like lower(concat(#{myEntityList.myEntity.myField},
'%'))"
While this works fine under Hibernate, other JPA providers may not support this syntax as
it is not described in the JPA specifications (1.0 and 2.0): the right hand side of the
"LIKE" term must be a String, not a function. For OpenJPA, this problem is
described in the following JIRA issue:
https://issues.apache.org/jira/browse/OPENJPA-920
Solution:
In order to make Seam-gen's entityLists supported by other JPA providers, we could
add a new Seam component JpaProviderUtils
@Name("jpaProviderUtils") {
public class JpaProviderUtils {
/**
* Returns the right hand side parameter of a like query (i.e. the X in
"someField LIKE X) from a given String parameter.
* The returned string all lower case and ends with a "%" wildcard, which
is an equivalent of Hibernate HQL expression "lower(concat(X, '%'))".
* Null is returned if the input parameter is null or empty. Note: if null is
returned, the LIKE query may be discarded by the JPA provider.
* @param likeParameter the like parameter to make lower case and wildcarded
* @return the lower case/wildcarded parameter; null is returned for null or empty
parameter
*/
public String getLikeParameter(String likeParameter) {
return (likeParameter!=null &&
likeParameter.length()>0?likeParameter.toLowerCase()+'%':null);
}
}
Then seam-gen must be modified to produce RESTRICTIONS such as:
"lower(myEntity.myField) like
#{jpaProviderUtils.getLikeParameter(myEntityList.myEntity.myField)}"
This is done simply by updating the seam-gen/src/EntityList.java.ftl (from Seam
2.1.2-SNAPSHOT):
-line 26 :
"lower(${componentName}.${property.name}.${componentProperty.name}) like
lower(concat(${'#'}{${listName}.${property.name}.${componentProperty.name}},
'%'))",
+line 26 :
"lower(${componentName}.${property.name}.${componentProperty.name}) like
${'#'}{jpaProviderUtils.getLikeParameter(${listName}.${property.name}.${componentProperty.name})}",
-line 31: "lower(${componentName}.${property.name}) like
lower(concat(${'#'}{${listName}.${property.name}}, '%'))",
+line 31: "lower(${componentName}.${property.name}) like
${'#'}{jpaProviderUtils.getLikeParameter(${listName}.${property.name})}",
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira