spring-projects / spring-data-relational

Spring Data Relational. Home of Spring Data JDBC and Spring Data R2DBC.
https://spring.io/projects/spring-data-jdbc
Apache License 2.0
765 stars 346 forks source link

Support for @Transient or transient [DATAJDBC-289] #514

Closed spring-projects-issues closed 4 years ago

spring-projects-issues commented 5 years ago

Moises Lejter opened DATAJDBC-289 and commented

We want to introduce Spring Data JDBC into one of our legacy projects, but ran into an issue where some of our VOs include properties in addition to those that are retrieved from the database and stored in the VO - but Spring JDBC errors out when trying to map a row from the corresponding table to the VO, since it doesn't find a column in the map corresponding to the additional properties in our VO.  We would like to be able to annotate these with either @Transient or just the Java transient qualifier, and have Spring Data JDBC ignore them when mapping a row to an entity


Affects: 1.0.2 (Lovelace SR2)

spring-projects-issues commented 5 years ago

Jens Schauder commented

@org.springframework.data.annotation.Transient should already work. Note that this is not the JPA @Transient annotation.

Please confirm that you are using the Spring Data @Transient annotation

spring-projects-issues commented 5 years ago

Jens Schauder commented

Batch closing resolved issues without a fix version and a resolution that indicates there is nothing to be released (Won't Do, Won't Fix, Invalid ...)

spring-projects-issues commented 4 years ago

benzen commented

I'm in the same situation described.

 

I'm using spring boot 2.3.1 with jdbc starter. Not certain that it's relevant but i'm also using project lombok.

 

 

When using the transient keyword, It seems to have no effect, I see the same error message as if the field was missing from db's table.

When using the annotation (org.springframework.data.annotation.Transient), i have the following stacktrace:

 

Required property idToken not found for class ....User!java.lang.IllegalStateException: Required property idToken not found for class ....User!
    at org.springframework.data.mapping.PersistentEntity.getRequiredPersistentProperty(PersistentEntity.java:160)
    at org.springframework.data.jdbc.core.convert.BasicJdbcConverter$ReadingContext.lambda$createInstanceInternal$0(BasicJdbcConverter.java:533)
    at org.springframework.data.relational.core.conversion.BasicRelationalConverter$ConvertingParameterValueProvider.getParameterValue(BasicRelationalConverter.java:264)
    at org.springframework.data.mapping.model.ClassGeneratingEntityInstantiator$EntityInstantiatorAdapter.extractInvocationArguments(ClassGeneratingEntityInstantiator.java:248)
    at org.springframework.data.mapping.model.ClassGeneratingEntityInstantiator$EntityInstantiatorAdapter.createInstance(ClassGeneratingEntityInstantiator.java:221)
    at org.springframework.data.mapping.model.ClassGeneratingEntityInstantiator.createInstance(ClassGeneratingEntityInstantiator.java:82)
    at org.springframework.data.relational.core.conversion.BasicRelationalConverter.createInstance(BasicRelationalConverter.java:147)
    at org.springframework.data.jdbc.core.convert.BasicJdbcConverter$ReadingContext.createInstanceInternal(BasicJdbcConverter.java:527)
    at org.springframework.data.jdbc.core.convert.BasicJdbcConverter$ReadingContext.mapRow(BasicJdbcConverter.java:387)
    at org.springframework.data.jdbc.core.convert.BasicJdbcConverter.mapRow(BasicJdbcConverter.java:323)
    at org.springframework.data.jdbc.core.convert.EntityRowMapper.mapRow(EntityRowMapper.java:67)
    at org.springframework.data.jdbc.repository.support.JdbcQueryLookupStrategy$PostProcessingRowMapper.mapRow(JdbcQueryLookupStrategy.java:152)
    at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:94)
    at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:61)
    at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:679)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:617)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:669)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:694)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:748)
    at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForObject(NamedParameterJdbcTemplate.java:236)
    at org.springframework.data.jdbc.repository.query.AbstractJdbcQuery.lambda$singleObjectQuery$1(AbstractJdbcQuery.java:115)
    at org.springframework.data.jdbc.repository.query.PartTreeJdbcQuery.execute(PartTreeJdbcQuery.java:98)
    at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor$QueryMethodInvoker.invoke(QueryExecutorMethodInterceptor.java:195)
    at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:152)
    at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:130)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:80)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:367)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
    at com.sun.proxy.$Proxy304.findByUsername(Unknown Source)
    at ca
spring-projects-issues commented 4 years ago

Jens Schauder commented

benzen Could you create a new issue for this, since this one is already closed for quite some time.

Please include the source code of the entity causing the problem including in this case the imports

spring-projects-issues commented 4 years ago

benzen commented

I ended up solving my original problem with a different approch than the one requireing to go through transient annotation. So i wont push this further