title: UserDefinedType not found by spring-data-cassandra
body: <p>based on the tutorial <a href="http://www.baeldung.com/spring-data-cassandra-tutorial" rel="nofollow noreferrer">spring-data-cassandra-tutorial</a> I'm experimenting with the UserDefinedType annotation.</p>
  
  <p>I upgraded the project to use spring-data-cassandra:1.5.0.BUILD-SNAPSHOT, added the attribute price to the book, implemented the corresponding UserDefinedType and added setInitialEntitySet and setUserTypeResolver to the configuration.</p>
  
  <p>When I then execute the BookRepositoryIntegrationTest against a cassandra 3.9, I get the following error:</p>
  
  <p><strong>org.springframework.data.mapping.model.MappingException: User type [price] not found</strong></p>
  
  <p>Any idea what I'm missing?</p>
  
  <p>Here my changes...</p>
  
  <p>Book.java:</p>
  
  <pre><code>package org.baeldung.spring.data.cassandra.model;
  
  import java.util.HashSet;
  import java.util.Set;
  import java.util.UUID;
  
  import org.springframework.cassandra.core.Ordering;
  import org.springframework.cassandra.core.PrimaryKeyType;
  import org.springframework.data.cassandra.mapping.Column;
  import org.springframework.data.cassandra.mapping.PrimaryKeyColumn;
  import org.springframework.data.cassandra.mapping.Table;
  
  @Table
  public class Book {
  
      @PrimaryKeyColumn(name = "id", ordinal = 0, type = PrimaryKeyType.CLUSTERED, ordering = Ordering.DESCENDING)
      private UUID id;
  
      @PrimaryKeyColumn(name = "title", ordinal = 1, type = PrimaryKeyType.PARTITIONED)
      private String title;
  
      @PrimaryKeyColumn(name = "publisher", ordinal = 2, type = PrimaryKeyType.PARTITIONED)
      private String publisher;
  
      @Column
      private Set&lt;String&gt; tags = new HashSet&lt;&gt;();
  
      private Price price;
  
      public Book(final UUID id, final String title, final String publisher, final Set&lt;String&gt; tags) {
          this.id = id;
          this.title = title;
          this.publisher = publisher;
          this.tags.addAll(tags);
      }
  }
  </code></pre>
  
  <p>pom.xml:</p>
  
  <pre><code>    &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.baeldung&lt;/groupId&gt;
      &lt;artifactId&gt;spring-data-cassandra&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
  
      &lt;name&gt;spring-data-cassandra&lt;/name&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
  
          &lt;org.springframework.version&gt;4.3.4.RELEASE&lt;/org.springframework.version&gt;
  
          &lt;org.springframework.data.version&gt;1.5.0.BUILD-SNAPSHOT&lt;/org.springframework.data.version&gt;
  
          &lt;junit.version&gt;4.12&lt;/junit.version&gt;
          &lt;org.slf4j.version&gt;1.7.12&lt;/org.slf4j.version&gt;
          &lt;logback.version&gt;1.1.3&lt;/logback.version&gt;
          &lt;cassandra-driver-core.version&gt;3.1.2&lt;/cassandra-driver-core.version&gt;
          &lt;cassandra-unit.version&gt;3.0.0.1&lt;/cassandra-unit.version&gt;
          &lt;maven-surefire-plugin.version&gt;2.19.1&lt;/maven-surefire-plugin.version&gt;        
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
              &lt;artifactId&gt;spring-data-cassandra&lt;/artifactId&gt;
              &lt;version&gt;${org.springframework.data.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
              &lt;version&gt;${org.springframework.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-test&lt;/artifactId&gt;
              &lt;version&gt;${org.springframework.version}&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.cassandraunit&lt;/groupId&gt;
              &lt;artifactId&gt;cassandra-unit-spring&lt;/artifactId&gt;
              &lt;version&gt;${cassandra-unit.version}&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
              &lt;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;org.cassandraunit&lt;/groupId&gt;
                      &lt;artifactId&gt;cassandra-unit&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.cassandraunit&lt;/groupId&gt;
              &lt;artifactId&gt;cassandra-unit&lt;/artifactId&gt;
              &lt;version&gt;${cassandra-unit.version}&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.datastax.cassandra&lt;/groupId&gt;
              &lt;artifactId&gt;cassandra-driver-core&lt;/artifactId&gt;
              &lt;version&gt;${cassandra-driver-core.version}&lt;/version&gt;
              &lt;optional&gt;true&lt;/optional&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
              &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
              &lt;version&gt;${org.slf4j.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;ch.qos.logback&lt;/groupId&gt;
              &lt;artifactId&gt;logback-classic&lt;/artifactId&gt;
              &lt;version&gt;${logback.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
              &lt;artifactId&gt;jcl-over-slf4j&lt;/artifactId&gt;
              &lt;version&gt;${org.slf4j.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
              &lt;artifactId&gt;log4j-over-slf4j&lt;/artifactId&gt;
              &lt;version&gt;${org.slf4j.version}&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.3.2&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.8&lt;/source&gt;
                      &lt;target&gt;1.8&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
                       &lt;plugin&gt;
                          &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                          &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
                          &lt;version&gt;${maven-surefire-plugin.version}&lt;/version&gt;
                          &lt;configuration&gt;
                              &lt;excludes&gt;
                                  &lt;exclude&gt;**/*IntegrationTest.java&lt;/exclude&gt;
                                  &lt;exclude&gt;**/*LiveTest.java&lt;/exclude&gt;
                              &lt;/excludes&gt;
                          &lt;/configuration&gt;
                      &lt;/plugin&gt;
                  &lt;/plugins&gt;
              &lt;/build&gt;
  
      &lt;profiles&gt;
          &lt;profile&gt;
              &lt;id&gt;integration&lt;/id&gt;
              &lt;build&gt;
                  &lt;plugins&gt;
                      &lt;plugin&gt;
                          &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                          &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
                          &lt;executions&gt;
                              &lt;execution&gt;
                                  &lt;phase&gt;integration-test&lt;/phase&gt;
                                  &lt;goals&gt;
                                      &lt;goal&gt;test&lt;/goal&gt;
                                  &lt;/goals&gt;
                                  &lt;configuration&gt;
                                      &lt;excludes&gt;
                                          &lt;exclude&gt;**/*LiveTest.java&lt;/exclude&gt;
                                      &lt;/excludes&gt;
                                      &lt;includes&gt;
                                          &lt;include&gt;**/*IntegrationTest.java&lt;/include&gt;
                                      &lt;/includes&gt;
                                  &lt;/configuration&gt;
                              &lt;/execution&gt;
                          &lt;/executions&gt;
                          &lt;configuration&gt;
                              &lt;systemPropertyVariables&gt;
                                  &lt;test.mime&gt;json&lt;/test.mime&gt;
                              &lt;/systemPropertyVariables&gt;
                          &lt;/configuration&gt;
                      &lt;/plugin&gt;
                  &lt;/plugins&gt;
              &lt;/build&gt;
          &lt;/profile&gt;
      &lt;/profiles&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>CassandraConfig.java</p>
  
  <pre><code>package org.baeldung.spring.data.cassandra.config;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.baeldung.spring.data.cassandra.model.Book;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.context.annotation.PropertySource;
  import org.springframework.core.env.Environment;
  import org.springframework.data.cassandra.config.CassandraClusterFactoryBean;
  import org.springframework.data.cassandra.config.CassandraEntityClassScanner;
  import org.springframework.data.cassandra.config.java.AbstractCassandraConfiguration;
  import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;
  import org.springframework.data.cassandra.mapping.CassandraMappingContext;
  import org.springframework.data.cassandra.mapping.SimpleUserTypeResolver;
  import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
  
  @Configuration
  @PropertySource(value = { "classpath:cassandra.properties" })
  @EnableCassandraRepositories(basePackages = "org.baeldung.spring.data.cassandra.repository")
  public class CassandraConfig extends AbstractCassandraConfiguration {
      private static final Log LOGGER = LogFactory.getLog(CassandraConfig.class);
  
      @Autowired
      private Environment environment;
  
      @Override
      protected String getKeyspaceName() {
          return environment.getProperty("cassandra.keyspace");
      }
  
      @Override
      @Bean
      public CassandraClusterFactoryBean cluster() {
          final CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean();
          cluster.setContactPoints(environment.getProperty("cassandra.contactpoints"));
          cluster.setPort(Integer.parseInt(environment.getProperty("cassandra.port")));
          LOGGER.info("Cluster created with contact points [" + environment.getProperty("cassandra.contactpoints") + "] " + "&amp; port [" + Integer.parseInt(environment.getProperty("cassandra.port")) + "].");
          return cluster;
      }
  
      @Override
      @Bean
      public CassandraMappingContext cassandraMapping() throws ClassNotFoundException {
          BasicCassandraMappingContext ctx = new BasicCassandraMappingContext();
          ctx.setInitialEntitySet(CassandraEntityClassScanner.scan(Book.class));
          ctx.setUserTypeResolver(new SimpleUserTypeResolver(cluster().getObject(), getKeyspaceName()));
          return ctx;
      }
  }
  </code></pre>
  
  <p>Price.java:</p>
  
  <pre><code>package org.baeldung.spring.data.cassandra.model;
  
  import org.springframework.data.cassandra.mapping.Column;
  import org.springframework.data.cassandra.mapping.UserDefinedType;
  
  @UserDefinedType
  public class Price {
  
      @Column
      private Double amount;
  
      @Column
      private String currency;
  
      public Price(Double amount, String currency) {
          this.amount = amount;
          this.currency = currency;
      }
  
      public Double getAmount() {
          return amount;
      }
  
      public String getCurrency() {
          return currency;
      }
  }
  </code></pre>