Skip to content

SpEL template behavior is inconsistent [DATAJPA-1266] #1597

Closed
@spring-projects-issues

Description

@spring-projects-issues

Jens Schauder opened DATAJPA-1266 and commented

The following tests succeed when added to ExpressionBasedStringQueryUnitTests

	@Test
	public void doesTemplatingWhenEntityNameSpelIsPresent() {

		StringQuery query = new ExpressionBasedStringQuery("select #{#entityName + 'Hallo'} from #{#entityName} u", metadata, SPEL_PARSER);

		assertThat(query.getQueryString(), is("select UserHallo from User u"));
	}

	@Test
	public void doesNotTemplatingWhenEntityNameSpelIsNotPresent() {

		StringQuery query = new ExpressionBasedStringQuery("select #{#entityName + 'Hallo'} from User u", metadata, SPEL_PARSER);

		assertThat(query.getQueryString(), is("select #{#entityName + 'Hallo'} from User u"));
	}

	@Test
	public void doesTemplatingWhenEntityNameSpelIsPresentForBindParameter() {

		StringQuery query = new ExpressionBasedStringQuery("select u from #{#entityName} u where name = :#{#something}", metadata, SPEL_PARSER);

		assertThat(query.getQueryString(), is("select u from User u where name = :"));
	}

We only apply templating if #\{#entityName\} is present in the query string. If we do so, we use the full-blown SpEL templating mechanism, i.e also other SpEL expressions get evaluated and replaced.

Also, SpEL expressions for bind parameters only get protected from this when they start with ?# not when they start with :#


No further details from DATAJPA-1266

Metadata

Metadata

Labels

in: query-parserEverything related to parsing JPQL or SQLtype: bugA general bug

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions