Replies: 5 comments 6 replies
-
|
Which part is it complaining about? Which element can it not find? I think i know where the error likely is. If you don't have existing data, you could always set that reference to use |
Beta Was this translation helpful? Give feedback.
-
|
Hello Evan, sorry for the late reply. In fact the situation is worst :( It is not possible to query a field referencing another collection even if the validation is disabled. Could you please have a look on it ? Many thanks. |
Beta Was this translation helpful? Give feedback.
-
|
I cannot push files from my organisation :( package org.acme;
import dev.morphia.annotations.Entity;
import dev.morphia.annotations.Id;
import org.bson.types.ObjectId;
import java.util.Objects;
@Entity(value = "child", useDiscriminator = false)
public class Child {
@Id
ObjectId id;
public Child() {
}
public Child(final ObjectId id) {
this.id = Objects.requireNonNull(id);
}
}package org.acme;
import dev.morphia.annotations.Entity;
import dev.morphia.annotations.Id;
import dev.morphia.annotations.Reference;
import org.bson.types.ObjectId;
import java.util.Objects;
@Entity(value = "parent", useDiscriminator = false)
public class Parent {
@Id
ObjectId id;
@Reference(lazy = true)
Child child;
public Parent() {
}
public Parent(final ObjectId id, final Child child) {
this.id = Objects.requireNonNull(id);
this.child = Objects.requireNonNull(child);
}
}package org.acme;
import dev.morphia.Datastore;
import dev.morphia.query.filters.Filters;
import jakarta.enterprise.context.ApplicationScoped;
import org.bson.types.ObjectId;
import java.util.Objects;
@ApplicationScoped
public class ParentRepository {
private final Datastore store;
public ParentRepository(final Datastore store) {
this.store = Objects.requireNonNull(store);
}
public Child store(final Child child) {
store.insert(child);
return child;
}
public Parent store(final Parent parent) {
store.insert(parent);
return parent;
}
public Parent findByChildId(final ObjectId objectId) {
return store.find(Parent.class).disableValidation()
.filter(Filters.eq("child.$id", objectId))
.first();
}
}package org.acme;
import com.mongodb.DBRefCodecProvider;
import com.mongodb.client.MongoClient;
import com.mongodb.client.model.Filters;
import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;
import org.bson.Document;
import org.bson.UuidRepresentation;
import org.bson.codecs.*;
import org.bson.types.ObjectId;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import java.util.List;
import static java.util.Arrays.asList;
import static org.bson.codecs.configuration.CodecRegistries.fromProviders;
import static org.bson.codecs.configuration.CodecRegistries.withUuidRepresentation;
import static org.junit.jupiter.api.Assertions.*;
@QuarkusTest
public class ParentRepositoryTest {
private static final Codec<Document> DEFAULT_CODEC = withUuidRepresentation(fromProviders(asList(new ValueCodecProvider(),
new CollectionCodecProvider(), new IterableCodecProvider(),
new BsonValueCodecProvider(), new DocumentCodecProvider(),
new DBRefCodecProvider(), // FIX here
new MapCodecProvider())), UuidRepresentation.STANDARD).get(Document.class);
@Inject
ParentRepository parentRepository;
@Inject
MongoClient mongoClient;
@Test
public void shouldStoreChild() {
assertDoesNotThrow(() -> {
final Child child = new Child();
parentRepository.store(child);
});
}
@Test
public void shouldStoreParent() {
assertDoesNotThrow(() -> {
final Parent parent = new Parent();
parentRepository.store(parent);
});
}
@Test
public void shouldStoreParentWithChild() {
final Child child = new Child(new ObjectId("65fd462a48d840308ed68001"));
parentRepository.store(child);
final Parent parent = new Parent(
new ObjectId("65fd461548d840308ed68000"),
child);
parentRepository.store(parent);
assertAll(
() -> JSONAssert.assertEquals(
//language=json
"""
{
"_id": {
"$oid": "65fd462a48d840308ed68001"
}
}
""",
mongoClient.getDatabase("sample").getCollection("child").find().first().toJson(DEFAULT_CODEC),
true
),
() -> JSONAssert.assertEquals(
//language=json
"""
{
"_id": {
"$oid": "65fd461548d840308ed68000"
},
"child": {
"$ref": "child",
"$id": {
"$oid": "65fd462a48d840308ed68001"
}
}
}
""",
mongoClient.getDatabase("sample").getCollection("parent").find().first().toJson(DEFAULT_CODEC),
true
)
);
}
@Test
public void shouldQueryParentHavingSpecificChild() {
final Child child = new Child(new ObjectId("65fd462a48d840308ed68001"));
parentRepository.store(child);
final Parent parent = new Parent(
new ObjectId("65fd461548d840308ed68000"),
child);
parentRepository.store(parent);
assertDoesNotThrow(() -> {
parentRepository.findByChildId(new ObjectId("65fd462a48d840308ed68001"));
});
assertNotNull(parentRepository.findByChildId(new ObjectId("65fd462a48d840308ed68001")));
}
@AfterEach
public void tearDown() {
List.of("child", "parent")
.forEach(collection -> mongoClient.getDatabase("sample").getCollection(collection)
.deleteMany(Filters.empty()));
}
}quarkus.mongodb.database=sample
quarkus.morphia.database=sample
quarkus.morphia.packages=org.acme
quarkus.morphia.map-sub-packages=true<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.acme</groupId>
<artifactId>morphiua-sample-parent-children</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<compiler-plugin.version>3.12.1</compiler-plugin.version>
<maven.compiler.release>17</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
<quarkus.platform.version>3.8.3</quarkus.platform.version>
<skipITs>true</skipITs>
<surefire-plugin.version>3.2.5</surefire-plugin.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>${quarkus.platform.artifact-id}</artifactId>
<version>${quarkus.platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.morphia</groupId>
<artifactId>quarkus-morphia</artifactId>
<version>0.5.0</version>
</dependency>
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
<version>1.5.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.platform.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>build</goal>
<goal>generate-code</goal>
<goal>generate-code-tests</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
<configuration>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<properties>
<skipITs>false</skipITs>
<quarkus.package.type>native</quarkus.package.type>
</properties>
</profile>
</profiles>
</project> |
Beta Was this translation helpful? Give feedback.
-
|
This exception occurs at the same place in if (hasNext() && property.isReference()) {
failValidation(segment);
}Quarkus is using version 2.3.4 of Morphia. The check on reference was not present in version 1.3.2 |
Beta Was this translation helpful? Give feedback.
-
|
hello @evanchooly , any news on this? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug
I am migrating an application using an old version of morphia to Quarkus.
I have notice a breaking change regarding the index validation on @reference property.
Before it was possible to référence them inside the index but now it is no more possible : a ValidationException is thrown instead.
To Reproduce
Steps to reproduce the behavior:
Have an entity with a property annotated with @reference
Reference the property inside @Index
Sample:
The change has been made on the resolve method in PathTarget when it checks if an element is present and if the field is a reference. Line 175.
Does this behavior is expected ?
Maybe a check can be added if we want to validateNames or not ?
Expected behavior
Application should start.
Index should be created.
** Please complete the following information: **
Additional context
Any example models, queries, and executable test cases you can supply will greatly help debugging your issue:
Beta Was this translation helpful? Give feedback.
All reactions