Я пытаюсь создать базу данных, которая содержит информацию о книгах, я создал эту сущность:
@Table(name = "books")
public class Book {
@PrimaryKeyColumn(
ordinal = 0,
type = PrimaryKeyType.PARTITIONED
)
private UUID bookId;
@PrimaryKeyColumn(
ordinal = 1,
type = PrimaryKeyType.PARTITIONED
)
private String title;
/**
* Key: surname
* Value: name
*/
@Frozen
@PrimaryKeyColumn(
ordinal = 2,
type = PrimaryKeyType.CLUSTERED
)
private Map<String, String> author;
@PrimaryKeyColumn(
ordinal = 3,
type = PrimaryKeyType.PARTITIONED
)
private LocalDate releaseDate;
private String genre;
}
Но когда я пытаюсь использовать @Table from com.datastax.driver.mapping.annotations.Table
, я получаю это исключениеКогда я пытаюсь сохранить объект в БД (таблица не создается):
Exception in thread "main" org.springframework.data.cassandra.CassandraInvalidQueryException: SessionCallback; CQL [INSERT INTO book (bookid,title,releasedate,author,genre) VALUES (0c9ae75a-f6ae-4916-a0d9-8cb289bf888c,'Historia','2000-10-10',{'Kowalski':'Jan'},'Historical');]; unconfigured table book; nested exception is com.datastax.driver.core.exceptions.InvalidQueryException: unconfigured table book
Я также пытался использовать аннотацию из org.springframework.data.cassandra.core.mapping.Table
Я получаю еще одну ошибку (у меня есть другая таблица,без каких-либо коллекций, это прекрасно работает с этой аннотацией):
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'epubLibraryApplication': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bookService' defined in file [D:\Studia\Inżynierka\epub-library\target\classes\pl\app\epublibrary\services\BookService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bookRepository': Cannot resolve reference to bean 'cassandraTemplate' while setting bean property 'cassandraTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cassandraTemplate' defined in class path resource [pl/app/epublibrary/config/CassandraConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.cassandra.core.CassandraAdminTemplate]: Factory method 'cassandraTemplate' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [pl/app/epublibrary/config/CassandraConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.cassandra.SessionFactory]: Factory method 'sessionFactory' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'session' defined in class path resource [pl/app/epublibrary/config/CassandraConfig.class]: Invocation of init method failed; nested exception is org.springframework.data.cassandra.CassandraInvalidQueryException: Query; CQL [CREATE TABLE IF NOT EXISTS books (bookid uuid, title text, releasedate date, author map<text, text>, genre text, PRIMARY KEY ((bookid, title, releasedate), author)) WITH CLUSTERING ORDER BY (author ASC);]; Invalid non-frozen collection type for PRIMARY KEY component author; nested exception is com.datastax.driver.core.exceptions.InvalidQueryException: Invalid non-frozen collection type for PRIMARY KEY component author
Есть ли способ использовать сопоставление объектов для создания этой таблицы или мне нужно использовать операторы CQL?