How to apply Spring Data projections in a Spring MVC controllers?

No it’s not, especially as projections are usually applied to the result of a query execution on a case by case basis. Thus they’re currently designed to be selectively applied to domain types. As of the latest Spring Data Fowler release train GA release the projection infrastructure can be used programmatically in Spring MVC controllers. … Read more

Why is an excerpt projection not applied automatically for a Spring Data REST item resource?

That works as designed. An excerpt projection is used whenever an instance of the target type (UserModel in your case) is used within in an _embedded clause. Thus the excerpt is some kind of preview used everywhere the resource itself is not rendered but pointed to. This is usually the case from collection resources or … Read more

Why is data getting stored with weird keys in Redis when using Jedis with Spring Data?

Ok, googled around for a while and found help at http://java.dzone.com/articles/spring-data-redis. It happened because of Java serialization. The key serializer for redisTemplate needs to be configured to StringRedisSerializer i.e. like this: <bean id=”jedisConnectionFactory” class=”org.springframework.data.redis.connection.jedis.JedisConnectionFactory” p:host-name=”${redis.server}” p:port=”${redis.port}” p:use-pool=”true”/> <bean id=”stringRedisSerializer” class=”org.springframework.data.redis.serializer.StringRedisSerializer”/> <bean id=”redisTemplate” class=”org.springframework.data.redis.core.RedisTemplate” p:connection-factory-ref=”jedisConnectionFactory” p:keySerializer-ref=”stringRedisSerializer” p:hashKeySerializer-ref=”stringRedisSerializer” /> Now the key in redis is vc:501381. Or … Read more

Create filter aggregation in spring

You can try below query. Static Imports import static org.springframework.data.mongodb.core.aggregation.Aggregation.*; import static org.springframework.data.mongodb.core.aggregation.ArrayOperators.Filter.filter; import static org.springframework.data.mongodb.core.aggregation.ComparisonOperators.Eq.valueOf; Code Aggregation aggregation = newAggregation( project().and(filter(“parts”) .as(“item”) .by(valueOf( “item.currentState”) .equalToValue( “Estimation Confirmed”))) .as(“parts”); ); List<outputType> results = mongoTemplate.aggregate(aggregation, inputType, outputType)

With Spring Data REST, why is the @Version property becoming an ETag and not included in the representation?

No, there is not. The ETag is the HTTP equivalent to what’s expressed as @Value property in the backend. Spring Data REST turns all backend related properties that have a corresponding mechanism in the HTTP protocol into exactly those: ids become URIs (and shouldn’t be part of the payload either), @LastModifiedDate properties become headers, @Version … Read more

FetchMode join makes no difference for ManyToMany relations in spring JPA repositories

Going through many forums and blogs to read for your problem (I guess you might have done that before posting it here) I too think that @Fetch(FetchMode.JOIN) will be ignored if you use the Query interface (e.g.: session.createQuery()) but it will be properly used if you use the Criteria interface. This is practically a bug … Read more

Spring Data + JPA with multiple datasources but only one set of Repositories

If you’re really using the different DataSourcees in a multi-tenant kind of way (essentially assigning a request to a DataSource and sticking with it for the entire request) you should have a look at AbstractRoutingDataSource. It essentially provides a way to keep a Map of DataSourcees as well as a callback method to return a … Read more

com.datastax.driver.core.exceptions.InvalidQueryException: unconfigured table schema_keyspaces

The problem is that Spring Data Cassandra (as of December 2015 when I write this) does not provide support for Cassandra 3.x. Here’s an excerpt from a conversation with one of the developers in the #spring channel on freenode: [13:49] <_amicable> Hi all, does anybody know if spring data cassandra supports cassandra 3.x? All dependencies … Read more

How To Configure MongoDb Collection Name For a Class in Spring Data

The only way you can currently achieve this is by annotating your domain class with @Document using the collection property to define the name of the collection instances of this class shall be persisted to. However, there’s a JIRA issue open that suggests adding a pluggable naming strategy to configure the ways class, collection and … Read more