Skip to content

Conversation

mp911de
Copy link
Member

@mp911de mp911de commented Sep 12, 2016

We now support Cassandra User-defined types. UDTs can be created using CQL generators and used inside of mapped domain classes. User-defined types can be used either raw as UDTValue that is passed through or as mapped object. Mapped UDTs must be annotated with @UserDefinedType. Types are included into schema generation so known and defined UDTs are created before any tables are created. UDTs can be used with set and list collection types and in primary keys. UDTs can also be used in repository query methods as query predicates.
Updating UDTs will update the whole UDT.

@UserDefinedType public class Address { String city; String country; } @Table public class Person { @Id String id; Address address; UDTValue genericUdt; } 

Related ticket: DATACASS-172
Depends on: #83

@mp911de
Copy link
Member Author

mp911de commented Sep 19, 2016

Reminder: Is there a better approach than registering an UserTypeResolver in the MappingContext? That requires users of Spring Boot and XML-Namespace support to take additional action.

@mohammeds1992
Copy link

Hi can some one please let me know when this feature will be merged to release branch?
If its going to take some time how can I use the build with this feature.

@mp911de
Copy link
Member Author

mp911de commented Oct 5, 2016

@shoaib627 Here's a link to the Ingalls Release Train containing all dates. It would be amazing getting feedback on that feature. The currently only way how to get this dependency is checking out my repo and the branch and building the project (mvn clean install). You can then add following dependencies to your project:

<dependency>     <groupId>org.springframework.data</groupId>     <artifactId>spring-cql</artifactId>     <version>1.5.0.DATACASS-172-SNAPSHOT</version> </dependency> <dependency>     <groupId>org.springframework.data</groupId>     <artifactId>spring-data-cassandra</artifactId>     <version>1.5.0.DATACASS-172-SNAPSHOT</version> </dependency>
@mp911de
Copy link
Member Author

mp911de commented Oct 18, 2016

@olivergierke maybe you want to take a look on this one?

mp911de and others added 5 commits October 25, 2016 09:43
Add tests. Add validations to Cql generators. Enhance JavaDoc. Create FieldSpecification for UDT fields.
We now support Cassandra User-defined types. UDTs can be created using CQL generators and used inside of mapped domain classes. User-defined types can be used either raw as UDTValue that is passed through or as mapped object. Mapped UDTs must be annotated with @UserDefinedType. Types are included into schema generation so known and defined UDTs are created before any tables are created. UDTs can be used with set and list collection types and in primary keys. UDTs can also be used in repository query methods as query predicates. Updating UDTs will update the whole UDT. @UserDefinedType public class Address { String city; String country; } @table public class Person { @id String id; Address address; UDTValue genericUdt; } The XML namespace support was extended with new schema versions to support provide a User Type resolver so UDTs can be resolved: <cassandra:mapping> <cassandra:user-type-resolver keyspace-name="${cassandra.keyspace}" /> </cassandra:mapping>
Leave schema files as they were with Spring Data Cassandra 1.4 and continue efforts with newly introduced Spring Data Cassandra 1.5 XSD files.
@jxblum
Copy link
Contributor

jxblum commented Nov 11, 2016

Merged to master in revisions 1865c31, a36e7be, 2195374 and c3584e6 for the Spring Data Cassandra 1.5 RC1 (Ingalls) release.

@jxblum
Copy link
Contributor

jxblum commented Nov 11, 2016

Committed to 2.0.x in revisions ac868d2, 84f680e, cfa8a61 and dcc34a2 for the Spring Data Cassandra 2.0 M1 (Kay) release.

@jxblum jxblum closed this Nov 11, 2016
@warwing
Copy link

warwing commented Nov 29, 2016

Hey,

I'm quite new to spring data in general, so may be my question is quite obvious, but...

I'am trying to understand how to use the UDTs - but I couldn't figure out how to "register" a UDT - so that it can be resolved by the mapping context.

I've seen this test:
https://github.com/spring-projects/spring-data-cassandra/blob/master/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/mapping/CreateTableSpecificationBasicCassandraMappingContextUnitTests.java

There are two variants:

  1. The approach with @CassandraType(type = Name.UDT, userTypeName = "human_udt") ...
  2. UserTypeResolver - but who can I get an instance of the UserType class? - In the test it's mocked...

I implemented the UDT as a class with @UserDefinedType annotation - and thought it should be usable without the @CassandraType annotation...
...for @table there is a Repository that seems to be responsible for registering the type.
Is there a corresponding concept for UDTs?

When I execute my test, the following error occurs:
org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.cassandra.mapping.CassandraMappingContext]: Factory method 'cassandraMapping' threw exception; nested exception is java.lang.IllegalArgumentException: UserTypeResolver must not be null

Best regards,

Alex

@mp911de mp911de deleted the issue/DATACASS-172 branch November 29, 2016 21:24
@mp911de
Copy link
Member Author

mp911de commented Nov 29, 2016

@warwing care to post your question on StackOverflow? This is not a general discussion forum.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants