Community
Participate
Working Groups
Build Identifier: Basically in org.eclipse.persistence.expressions.Expression the methods dateDifference (both overloads), dateName, and datePart put the parameters in the wrong order (at least on SQL Server). The datePart should come first, and even though appears in code to do this, the baseExpression of the function is the date. Reproducible: Always
Created attachment 176512 [details] Patch for 322602 Patch added that fixed the problem for me. Note, I usually access this w/ a custom FunctionExpressionImpl from the JPA criteria side instead of using the EclipseLink libraries directly. For instance, here is my datePart function: @SuppressWarnings({ "unchecked", "rawtypes" }) public static Expression<Integer> datePart(EntityManager em, Expression<Date> date, DatePart datePart) { org.eclipse.persistence.expressions.Expression dateExpr = ((InternalSelection) date).getCurrentNode(); ExpressionOperator anOperator = dateExpr.getOperator(ExpressionOperator.DatePart); FunctionExpression expression = new FunctionExpression(); org.eclipse.persistence.expressions.Expression datePartLiteral = dateExpr.literal(datePart.toString()); expression.setBaseExpression(datePartLiteral); expression.addChild(datePartLiteral); expression.addChild(dateExpr); expression.setOperator(anOperator); return new FunctionExpressionImpl(em.getMetamodel(), ClassConstants.INTEGER, expression, Arrays.asList(em.getCriteriaBuilder(). literal(datePart.toString()), date), "datepart"); }
Setting target and priority see: http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines for more information on the meanings of these fields.
This should probably be patched in SQLServerPlatform and on SybasePlatform to ensure the changes do not break any platforms that are working with the current setup. You should write methods on those platforms similar to the method written on SymfowarePlatform. e.g.: protected static ExpressionOperator addDate() { ExpressionOperator exOperator = new ExpressionOperator(); exOperator.setSelector(ExpressionOperator.AddDate); Vector<String> v = NonSynchronizedVector.newInstance(4); v.addElement("ADD_DATE("); v.addElement(", "); v.addElement(", '"); v.addElement("')"); exOperator.printsAs(v); exOperator.bePrefix(); int[] indices = new int[3]; indices[0] = 0; indices[1] = 2; indices[2] = 1; exOperator.setArgumentIndices(indices); return exOperator; } The "indices" array is used to reorder the arguments. In fact, you may be able to use a number of the Symfoware date functions as a guideline. The new operator switched in the initializePlatformOperators() method of each platform. The additional advantage of this is that you can subclass SybasePlatform or SQLServerPlatform and take advantages of the changes right away by making use of your subclass.
Thanks for the info, this helps me a lot in not having to edit the original source of EclipseLink in my project to support this. I will provide a new patch in not too long (little busy now). At the least, on Expression, the javadoc should be updated to remove the Sybase reference, remove the SQL example, or correct the SQL example.
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink