Nitrite/Java: 4.0.1 - Issue with repo entities - Object must implements Mappable? #17
|
Hi! This is my repo object. import org.dizitart.no2.index.IndexType
import org.dizitart.no2.repository.annotations.Entity
import org.dizitart.no2.repository.annotations.Id
import org.dizitart.no2.repository.annotations.Index
@Entity(
value = "server",
indices = [Index(value = ["installed"], type = IndexType.UNIQUE)]
)
data class Server(
@Id
val installed: Boolean = false
)But when I want to insert data, I get this exception: val serverRepo = db.getRepository(Server::class.java)
val serverDto = Server(true)
serverRepo.update(serverDto) |
Replies: 0 comments 6 replies
|
Please either refer to the document here or the junit test classes available in the repo. |
|
Actually nitrite 4.x has been heavily refactored from 3.x. The jackson serialization functionality has been separated out in a different library - nitrite-jackson-mapper. So you have to add this dependency in your java project. MVStoreModuleBuilder builder = MVStoreModule.withConfig();
builder.compress(true);
builder.autoCommit(false);
builder.filePath(fileName);
MVStoreModule storeModule = builder.build();
NitriteBuilder nitriteBuilder = Nitrite.builder()
.loadModule(new JacksonMapperModule())
.loadModule(storeModule);
Nitrite db = nitriteBuilder.openOrCreate("test-user", "test-password");If you are using kotlin, you should use potassium-nitrite library instead of nitrite, which have this jackson dependency already. You can just create a db instance as below val db = nitrite {
loadModule(MVStoreModule(fileName))
} |
|
You need the below gradle build script plugins {
id 'org.jetbrains.kotlin.jvm' version '1.6.10'
}
group 'org.dizitart.demo'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
maven {
url 'http://oss.sonatype.org/content/repositories/snapshots'
}
}
dependencies {
implementation(platform("org.dizitart:nitrite-bom:4.0.1-SNAPSHOT"))
implementation('org.dizitart:nitrite-mvstore-adapter')
implementation('org.dizitart:potassium-nitrite')
implementation('org.dizitart:nitrite-jackson-mapper')
implementation('org.dizitart:nitrite-spatial')
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jdk8")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation ("ch.qos.logback:logback-classic:1.2.10")
}
compileKotlin {
kotlinOptions.jvmTarget = "11"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "11"
}And below kotlin code fun main() {
val dbPath = "/tmp/nitrite-demo"
val storeModule = MVStoreModule.withConfig()
.filePath(dbPath)
.build()
val db = nitrite {
loadModule(storeModule)
}
val repo = db.getRepository<Server>()
repo.insert(Server(false))
repo.insert(Server(true))
println("All servers: " + repo.find().toList())
}
@Entity(
value = "server",
indices = [Index(value = ["installed"], type = IndexType.UNIQUE)]
)
data class Server(
@Id
val installed: Boolean = false
)I hope this helps to boot your application. |
|
Java platform api constraint only applies constraints to the version on the existing dependency graph. It does not bring in new dependencies. That is why you need to specify the dependencies here specifically. Platform api will take care of the versions. |
Actually nitrite 4.x has been heavily refactored from 3.x. The jackson serialization functionality has been separated out in a different library - nitrite-jackson-mapper. So you have to add this dependency in your java project.
If you are using kotlin, you should use potassium-nitrite library instead of nitrite, whi…