Hello everyone,
I have a problem when I run my project
Caused by: java.lang.IllegalArgumentException: At least one JPA metamodel must be present!
I don't know how to fix it.I saw some same topic and They said this problem in file pom.xml. But I don't see anything wrong in my file pom.xml. So Can somebody help me
This is my Code
File pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.7</version>
DemoApplication
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
#SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
Model with #Entity
package com.example.model;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table(name = "contact")
public class Contact implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "id", nullable = false)
private int id;
#Column(name = "name", nullable = false)
private String name;
#Column(name = "email")
private String email;
#Column(name = "phone")
private String phone;
public Contact() {
super();
}
public Contact(int id, String name, String email, String phone) {
super();
this.id = id;
this.name = name;
this.email = email;
this.phone = phone;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}
I don't know how to fix it
You have in your pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
But you don't have any classes with #Entity annotation defined. You need at least one of those to successfully create the Entity Manager. If not remove the above dependency.
Your SpringBootApplication relies in package com.example.demo; and your entity in package com.example.model; . Per Default #SpringBootApplication will try to look into its package and below. It cannot find your entities as they are in a different package, unless you specify it explicitly e.g. via
#EntityScan(basePackages = "com.example.model")
Related
I am having a problem while starting my Spring Boot application:
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'coffeeService': Unsatisfied dependency expressed through field 'coffeeRepository': Error creating bean with name 'coffeeRepository' defined in com.coffeetime.coffeeshop.repository.CoffeeRepository defined in #EnableJpaRepositories declared on CoffeeshopApplication: Not a managed type: class com.coffeetime.coffeeshop.domain.Coffee
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'coffeeRepository' defined in com.coffeetime.coffeeshop.repository.CoffeeRepository defined in #EnableJpaRepositories declared on CoffeeshopApplication: Not a managed type: class com.coffeetime.coffeeshop.domain.Coffee
Caused by: java.lang.IllegalArgumentException: Not a managed type: class com.coffeetime.coffeeshop.domain.Coffee
The version of Spring Bot is 3.0 and Java is 17 (Most updated ones from Initialzr).
I want to use H2 as in-memory database:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
The package hierarchy is convenient to scan entities. So, I think it is not necessary to add #EntityScan (I tried it as well)
File structure
Here is application.properties:
spring.datasource.url=jdbc:h2:mem:coffeeshopdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=pass1234
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.show-sql=true
spring.h2.console.enabled=true
spring.jpa.defer-datasource-initialization=true
Repository
import org.springframework.data.jpa.repository.JpaRepository;
import com.coffeetime.coffeeshop.domain.Coffee;
public interface CoffeeRepository extends JpaRepository<Coffee, Long>{
}
And the entity:
#Entity
#Table(name = "coffee")
public class Coffee {
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
#Column(name = "name")
#NotEmpty(message = "Coffee name cannot be empty")
private String name;
#Column(name = "amount")
#NotNull(message = "Coffee price cannot be empty")
#Min(value = 0, message = "Coffee price must be greater than or equal to 0")
private BigDecimal amount;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public BigDecimal getAmount() {
return amount;
}
public void setAmount(BigDecimal amount) {
this.amount = amount;
}
}
I checked the similar problem in this thread, no any answer worked. I suspect about H2.
Thanks
I tried using #EntityScan and playing with application.properties. But still same error.
I found the problem. Spring Boot 3.0.0 version started using jakarta instead of javax.persistence. Reorganizing the imports solved the problem.
I am using mapstruct to map my model to my DTO.
I want to search for a record by the full name.
I do not understand why I get the following errors:
Error creating bean with name 'customerController'
Error creating bean with name 'customerServiceImpl'
Error creating bean with name 'customerRepository'
No property name found for type Customer!
this is my project
public interface CustomerMapper {
CustomerMapper INSTANCE = Mappers.getMapper(CustomerMapper.class);
#Mapping(source = "lastName", target = "lastName")
CustomerDTO customerToCustomerDTO(Customer customer);
}
#Data
public class CustomerDTO {
private String firstName;
private String lastName;
}
#Data
#Entity
#Getter
#Setter
public class Customer {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String firstName;
private String name;
}
#Data
#NoArgsConstructor
#AllArgsConstructor
public class CustomerListDTO {
List<CustomerDTO> categories;
}
#Controller
#RequestMapping("api/v1/customers")
public class CustomerController {
private final CustomerService customerService;
public CustomerController(CustomerService customerService) {
this.customerService = customerService;
}
#GetMapping("{name}")
public ResponseEntity<CustomerDTO> getCustomerByName(#PathVariable String name) {
return new ResponseEntity<>(
customerService.getCustomerByName(name), HttpStatus.OK
);
}
public interface CustomerRepository extends JpaRepository<Customer, Long> {
Customer findByName(String x);
}
public interface CustomerService {
CustomerDTO getCustomerByName(String name);
}
#AllArgsConstructor
#Service
public class CustomerServiceImpl implements CustomerService {
CustomerMapper customerMapper;
CustomerRepository customerRepository;
#Override
public CustomerDTO getCustomerByName(String lastName) {
return customerMapper.customerToCustomerDTO(customerRepository.findByName(lastName));
}
}
This is a potential fix: would be to map the below in the CustomerMapper, but to me it doesn't feel right.
#Mapping(source = "name", target = "lastName")
#Mapping(source = "firstName", target = "firstName")
In the documentation, it is said that you can map whatever field from model to DTO, I think there might be something wrong in my code.
The way I try implementing in the repo, service, controller.
Edit:
Maybe a solution would be to use DTO in Repository?
Update:
#Override
public CustomerDTO getCustomerByName(String lastName) {
return customerRepository.findByName(lastName).map(customerMapper::customerToCustomerDTO);
}
.map cannot be used.
for .map to be used I should use code like this
.findAll()
.stream()
.map(customerMapper::customerToCustomerDTO)
.collect(Collectors.toList());
I am using the findByName method however, that doesn't have access to .map.
How can I solve that problem?
EDIT
this is how my Customer I think should look like
#Data
#NoArgsConstructor
#AllArgsConstructor
public class CustomerDTO {
private String id;
private String firstName;
private String lastName;
}
"No property name found for type Customer!"
In you table costumer you have a column with name "name"?
Below I made some changes in your code, however if you need to find by name your repository needs to find correct search. When you use findByName only return rows where name is equals to name passed in parameter. Example: findByName("Scilla") only return rows where column name is equals to "Scilla", if a column name have values like "scilla" (lower) or "Scilla abc" this entries was not returned by query.
Method findByName with value "Scilla" generate this query:
select * from customer where name = 'Scilla';
Code changes
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
public interface CustomerRepository extends JpaRepository<Customer, Long> {
Customer findByLastName(String lastName);
List<Customer> findByLastNameContainingIgnoreCase(String name);
List<Customer> findByLastNameContaining(String name);
}
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
#Mapper
public interface CustomerMapper {
CustomerMapper INSTANCE = Mappers.getMapper(CustomerMapper.class);
CustomerDTO customerToCustomerDTO(Customer customer);
Customer toDomain(CustomerDTO customerDTO);
}
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import lombok.Data;
import lombok.NoArgsConstructor;
#Data
#Entity
#NoArgsConstructor
public class Customer {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String firstName;
private String lastName;
}
import lombok.Data;
#Data
public class CustomerDTO {
private String firstName;
private String lastName;
}
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
#RestController
#RequestMapping("api/v1/customers")
public class CustomerController {
private final CustomerService customerService;
public CustomerController(CustomerService customerService) {
this.customerService = customerService;
}
#GetMapping("{name}")
public ResponseEntity<CustomerDTO> getCustomerByName(#PathVariable String name) {
return new ResponseEntity<>(
customerService.getCustomerByName(name), HttpStatus.OK
);
}
#PostMapping
public ResponseEntity<CustomerDTO> getCustomerByName(#RequestBody CustomerDTO customerDTO ) {
return new ResponseEntity<>(
customerService.save(customerDTO), HttpStatus.OK
);
}
}
Important
Below put Spring Data query and translation query.
List<Customer> findByLastNameContainingIgnoreCase(String name)
select * from customer where last_name ilike = '%name%';
pom.xml definition
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
<org.mapstruct.version>1.4.1.Final</org.mapstruct.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.4.1.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<release>11</release>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
To map your Customer entity to DTO and use it in the Spring application you should use the following mapper (with parameter componentModel = "spring"):
#Mapper(
componentModel = "spring",
nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT,
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,
nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE
)
public interface CustomerMapper {
#Mapping(target = "lastName", source = "name")
CustomerDto toDto(Customer customer);
}
MapStruct doesn't know how to map name property in your entity to lastName property in the DTO, so you have to specify this in #Mapping annotation.
(I also recommend to use specified values of 'strategy' parameters - you can check their purpose in javadoc.)
In this case, MapStruct generates an appropriate Spring bean with the implementation of your mapper, something like this:
#Component
public class CustomerMapperImpl {
public CustomerDto toDto(Customer customer) {
CustomerDto dto = new CustomerDto();
if (customer != null) {
if (customer.getFirstName() != null) {
dto.setFirstName(customer.getFirstName());
}
if (customer.getName() != null) {
dto.setLastName(customer.getName());
}
}
return dto;
}
}
So Spring will be able to inject that bean in your service (don't forget to correct findByName method of your repo to return Optional):
#RequiredArgsConstructor
#Service
public class CustomerServiceImpl implement CustomerService {
private final CustomerRepo repo;
private final CustomerMapper mapper;
#Override
public Optional<CustomerDto> getByName(#NonNull String name) {
return repo.findByName(name).map(mapper::toDto)
}
#Override
public List<CustomerDto> getAll() {
return repo.findAll().stream().map(mapper::toDto).collect(Collectors.toList());
}
}
And then use this service in your REST controller:
#RequiredArgsConstructor
#RestController
#RequestMapping("api/v1/customers")
public class CustomerController {
private final CustomerService service;
#GetMapping("/{name}")
public CustomerDto getByName(#PathVariable String name) {
return service.getByName()
.orElseThrow(() -> new ResponseStatusException("Customer not found"));
}
#GetMapping
public List<CustomerDto> getAll() {
return service.getAll();
}
}
Don't forget to configure your project to use MapStruct and Lombok together:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
I am trying to set up liquibase in my spring boot application. What I am trying is to create change sets between my Entities and my DB with mvn liquibase:diff
Here is example of one of my entities:
package com.example.start.project.entity;
import static com.example.start.project.entity.DatabaseConstants.CREATED_AT;
import static com.example.start.project.entity.DatabaseConstants.CREATED_BY;
import static com.example.start.project.entity.DatabaseConstants.LEGACY_ID;
import static com.example.start.project.entity.DatabaseConstants.MODIFIED_AT;
import static com.example.start.project.entity.DatabaseConstants.MODIFIED_BY;
import static com.example.start.project.entity.DatabaseConstants.SCHEMA_NAME;
import static com.example.start.project.entity.DatabaseConstants.TABLE_PREFIX;
import static com.example.start.project.entity.PlantEntity.TSN_PREFIX;
import java.time.ZonedDateTime;
import java.util.UUID;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import org.springframework.data.annotation.Immutable;
#Entity
#Table(schema = SCHEMA_NAME, name = TABLE_PREFIX + TSN_PREFIX + "PLANT")
#Immutable
public class PlantEntity {
/** Table short name. */
static final String TSN = "PLNT";
/** Table short name as prefix. */
static final String TSN_PREFIX = TSN + "_";
/** Id column name */
static final String ID_COLUMN = TSN_PREFIX + DatabaseConstants.ID;
private static final long serialVersionUID = 1L;
#Id
#Column(name = ID_COLUMN)
private UUID id;
#Column(name = TSN_PREFIX + LEGACY_ID)
private Long legacyId;
#Column(name = TSN_PREFIX + "NUMBER")
private String number;
#Column(name = TSN_PREFIX + "NAME")
private String name;
#Column(name = TSN_PREFIX + "TYPE")
private String type;
#Column(name = TSN_PREFIX + CREATED_BY)
private String createdBy;
#Column(name = TSN_PREFIX + CREATED_AT)
private ZonedDateTime createdAt;
#Column(name = TSN_PREFIX + MODIFIED_BY)
private String modifiedBy;
#Column(name = TSN_PREFIX + MODIFIED_AT)
private ZonedDateTime modifiedAt;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public Long getLegacyId() {
return legacyId;
}
public void setLegacyId(Long legacyId) {
this.legacyId = legacyId;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public ZonedDateTime getCreatedAt() {
return createdAt;
}
public void setCreatedAt(ZonedDateTime createdAt) {
this.createdAt = createdAt;
}
public String getModifiedBy() {
return modifiedBy;
}
public void setModifiedBy(String modifiedBy) {
this.modifiedBy = modifiedBy;
}
public ZonedDateTime getModifiedAt() {
return modifiedAt;
}
public void setModifiedAt(ZonedDateTime modifiedAt) {
this.modifiedAt = modifiedAt;
}
}
And here is my POM looks like:
*******
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>3.8.8</version>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-cdi</artifactId>
<version>3.8.8</version>
</dependency>
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-hibernate5</artifactId>
<version>3.8</version>
</dependency>
</dependencies>
</dependencyManagement>
*********
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.8.8</version>
<configuration>
<propertyFile>liquibase/liquibase.properties</propertyFile>
<changeLogFile>liquibase/changeLogs/database.yaml</changeLogFile>
<driver>${test.jdbc.driver}</driver>
<url>${test.jdbc.url}?currentSchema=${test.jdbc.schema}</url>
<username>${test.jdbc.userName}</username>
<password>${test.jdbc.password}</password>
<!--defaultSchemaName>${test.jdbc.schema}</defaultSchemaName>-->
<changelogSchemaName>${test.jdbc.schema}</changelogSchemaName>
<referenceDriver>liquibase.ext.hibernate.database.connection.HibernateDriver</referenceDriver>
<referenceUrl>hibernate:spring:com.example.start.project.entity?dialect=org.hibernate.dialect.PostgreSQL95Dialect</referenceUrl>
<diffChangeLogFile>${project.build.directory}/startup.db-diff.yaml</diffChangeLogFile>
<outputChangeLogFile>${project.build.directory}/db-initial.yaml</outputChangeLogFile>
<!-- Syntax: [objecttype from liquibase.structure.core]:[regex matching name] -->
<diffExcludeObjects>sequence:.*_SEQ</diffExcludeObjects>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
<logging>debug</logging>
</configuration>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>${test.jdbc.groupId}</groupId>
<artifactId>${test.jdbc.artifactId}</artifactId>
<version>${test.jdbc.version}</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>${java-validation-api.version}</version>
</dependency>
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-hibernate5</artifactId>
<version>${liquibase.hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
When I run mvn liquibase:diff i got No changesets to add. even I have few entities and my DB is empty. DB is Postgress.
I think that issue is with referenceUrl:
<referenceUrl>hibernate:spring:com.example.start.project.entity?dialect=org.hibernate.dialect.PostgreSQL95Dialect</referenceUrl>
and that liquibase is not able to find my entities.
Entities are placed in different maven module than from where I am running mvn liquibase:diff but this module has reference to it.
Does anyone see what I am doing wrong. Thanks in advance.
You can add this liquibase plugin with a path to liquibase properties file:
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.4.1</version>
<configuration>
<propertyFile>src/main/resources/liquibase.properties</propertyFile>
</configuration>
</plugin>
And liquibase.properties should look like this:
url=jdbc:oracle:thin:#1.1.1.1:1521:ORCL
username=name
password=pas
driver=oracle.jdbc.driver.OracleDriver
outputChangeLogFile=src/main/resources/liquibase-outputChangeLog.xml
changeLogFile=classpath:/db/changelog/db.changelog-master.xml
referenceUrl=hibernate:spring:com.your.model?dialect=org.hibernate.dialect.Oracle12cDialect
diffChangeLogFile=target/db.changelog-diff.xml
Then: mvn liquibase:diff
I am trying to use #CreationTimestamp for an instance variable of Instant type.
I am using hibernate.version 5.2.10 and imported import org.hibernate.annotations.*;
but still showing No Default Proposals.
Here is my code
import java.time.Instant;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import org.hibernate.annotations.*;
#MappedSuperclass
public class AbstractEntity {
#Id
#Column(nullable=false,updatable=false)
#GeneratedValue(strategy=GenerationType.IDENTITY)
protected Long id;
#CreationTimestamp
protected Instant created;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Instant getCreated() {
return created;
}
You can try to add #EntityListeners(AuditingEntityListener.class) annotation on the class.
Not sure how it worked now
here is what I did
Used jackson-datatype-jsr310
and used #EntityScan in my main class
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.8.7</version>
</dependency>
As I got issues with spring-data-cassandra with docker as describer here I switched to use com.datastax.cassandra library for cassandra operations but I am getting issues while mapping the resulted object using entity mapper as per this link
Here is my code ...
public String getUser(String userName) {
Mapper<User> mapper = manager.mapper(User.class);
User result = mapper.get(userName); // no issue getting User
String accountNum = result.getAccountId();
return accountNum ;
}
public Account getAccount(String accountNum){
Mapper<Account> mapper = manager.mapper(Account.class);
Account account = mapper.get(accountNum); // getting error here
return account;
}
Account.java
#Table(name = "account")
public class Account {
#PartitionKey
private String accountNum;
private String accountsubtype;
private float currentbalance;
private String customertype;
private String firstname;
private boolean isactive;
private String payments;
private String status;
....
//Getters & Setters
}
pom.xml dependecies
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-mapping</artifactId>
<version>3.0.0</version>
</dependency>