Uploaded image for project: 'Hibernate ORM'
  1. HHH-8434

CriteriaUpdate doesn't separate multiple assignments in rendered string

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects versions: None
    • Fix versions: 4.3.0.Beta5
    • Components: None
    • Labels:
      None
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true
    • Sprint:

      Description

                  CriteriaUpdate<Item> update =
                      criteriaBuilder.createCriteriaUpdate(Item.class);
                  Root<Item> i = update.from(Item.class);
                  update.set(
                      i.get(Item_.active),
                      true
                  );
                  update.set(
                      i.get(Item_.name),
                      "Foo"
                  );
      
                  int updatedEntities = em.createQuery(update).executeUpdate();
      

      Renders invalid HQL:

      update Item as generatedAlias0 set generatedAlias0.active = :param0generatedAlias0.name = :param1, 
      

      Note the missing comma and space between ":param0" and "generatedAlias0.name" and the comma at the end.

      Simple fix, the code in CriteriaUpdateImpl appending the comma and space is wrong:

      
      	private void renderAssignments(StringBuilder jpaql, RenderingContext renderingContext) {
      		jpaql.append( " set " );
      		boolean first = true;
      		for ( Assignment assignment : assignments ) {
      			jpaql.append( assignment.attributePath.render( renderingContext ) )
      					.append( " = " )
      					.append( assignment.value.render( renderingContext ) );
      			if ( ! first ) { // Should be !last
      				jpaql.append( ", " );
      			}
      			first = false;
      		}
      	}
      

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: