Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring Data JDBC documentation has no information about SpEL support #1719

Closed
sergey-morenets opened this issue Jan 14, 2024 · 4 comments
Closed
Assignees
Labels
type: documentation A documentation update

Comments

@sergey-morenets
Copy link

Hi

Spring Data JDBC 3.2.0 introduced SpEL support for @Table/@column annotations:
#1325

However current reference documentation contains no information about how to use this feature and what are the benefits:
https://docs.spring.io/spring-data/relational/reference/jdbc/mapping.html

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 14, 2024
@christophstrobl christophstrobl added type: documentation A documentation update and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 16, 2024
@christophstrobl
Copy link
Member

Thanks for bringing this up. There's a litte documentation in the release notes which should also be added to the Naming Strategy section of the reference documentation.

@sergey-morenets
Copy link
Author

Thank you, @christophstrobl

I asked about documentation because this feature just doesn't work for me.

I added a Spring bean:

	@Bean
	String productName() {
		return "PRODUCTS";
	}

And then used this bean in the table name:


@Table("#{productName}")
public class Product implements Persistable<Integer> {

However I got an exception:

Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'productName' cannot be found on null

@sergey-morenets
Copy link
Author

I also tried to declare another Spring bean:

	@Bean
	Product product() {
		Product product = new Product();
		product.setName("PRODUCTS");
		return product;
	}
@Table("#{product.name}")
public class Product implements Persistable<Integer> {

But still got an exception:

Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'product' cannot be found on null

@mp911de
Copy link
Member

mp911de commented Jan 18, 2024

I filed a ticket to update our docs. By default, the mapping layer does not define a root object as we need to construct column and table names before even having an instance of an entity. Please have a look at org.springframework.data.spel.spi.EvaluationContextExtension (see https://github.com/spring-projects/spring-security/blob/main/data/src/main/java/org/springframework/security/data/repository/query/SecurityEvaluationContextExtension.java for a reference implementation) on how to contribute functions and objects into Spring Data's SpEL realm.

schauder added a commit that referenced this issue Aug 7, 2024
schauder added a commit that referenced this issue Aug 7, 2024
@schauder schauder added this to the 3.2.9 (2023.1.9) milestone Aug 7, 2024
@schauder schauder self-assigned this Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation update
Projects
None yet
Development

No branches or pull requests

5 participants