Morphia.createDatastore((com.mongodb.client.MongoClient) mongoClient, DATABASE) #1875
Replies: 11 comments 8 replies
-
Running 'test':
After:
Using (your) 'employees' example: @Entity("employees")
@Indexes(@Index(options = @IndexOptions(name = "salary"), fields = @Field("salary")))
class Employee {
@Id
private ObjectId id;
private String name;
private Integer age;
@Reference
private Employee manager;
@Reference
private List<Employee> directReports = new ArrayList<>();
@Property("wage")
private Double salary;
Employee() {
}
Employee(String name, Double salary) {
this.name = name;
this.salary = salary;
}
public List<Employee> getDirectReports() {
return directReports;
}
public void setDirectReports(List<Employee> directReports) {
this.directReports = directReports;
}
public ObjectId getId() {
return id;
}
public Employee getManager() {
return manager;
}
public void setManager(Employee manager) {
this.manager = manager;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Double getSalary() {
return salary;
}
public void setSalary(Double salary) {
this.salary = salary;
}
} Getting:
Any pointers? |
Beta Was this translation helpful? Give feedback.
-
Is there any more to the exception? a |
Beta Was this translation helpful? Give feedback.
-
As "implementation("dev.morphia.morphia:morphia-core:2.2.6")" won't run so I compiled & build WAR, JAR to EAR using Gradle 7.4.2 with:
My EAR now won't deploy on WildFly 26.1.0.Final:
|
Beta Was this translation helpful? Give feedback.
-
I'm not a gradle guy but it looks like using the |
Beta Was this translation helpful? Give feedback.
-
I have been using MongoDB with Hibernate OGM, ORM on WildFly & Gradle for 3+ years with only a few minor problems or issues. I was hoping to use an 'ODM' such as 'Morphia', but I can't get an easy example work with it using;
I'm afraid I can't spend anymore time & effort on it & I'll switch to use pure MongoDB with:
Thanks for your support. |
Beta Was this translation helpful? Give feedback.
-
Cleared Cache etc. with:
So Gradle download all JARs again. Remove 'try ... catch' to show 'Exception': :
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the detailed suggestions. GoStopHandle.ear
GoStopHandleJAR.jar
GoStopHandleWAR.war:
BTW - Gradle "So, in other words, adding an entry to providedCompile or providedRuntime will cause that dependency to be excluded from the war file". https://stackoverflow.com/questions/20707543/gradle-how-to-exclude-jar-from-a-war/ Only one 'morphia' JAR:
@:
Two JARs with 'mongo' on WildFly ...
|
Beta Was this translation helpful? Give feedback.
-
I just noticed the driver version you have in there. Morphia is only tested against driver versions 4.2.x and newer. You'll want to update that dependency for sure. |
Beta Was this translation helpful? Give feedback.
-
and there's nowhere underneath your wildfly installation that you have any morphia or mongodb java driver jars installed anywhere? |
Beta Was this translation helpful? Give feedback.
-
I've had use "The MongoDB Java Driver uber-artifact, containing the legacy driver, the mongodb-driver, mongodb-driver-core, and bson" @ https://mvnrepository.com/artifact/org.mongodb/mongo-java-driver/3.12.11 This is: the Apr 22, 2022 version which works with Hibernate + OGM + MongoDB. Also added: 'mongodb-driver-core-4.6.0.jar' & 'bson-4.6.0.jar' to my EAR:
Get same Exception:
|
Beta Was this translation helpful? Give feedback.
-
Morphia finally working ... Had to upgraded WildFly 26.1.0.Final to 26.1.1.Final. dev.morphia.morphia:morphia-core:2.2.7 to dev.morphia.morphia:morphia-core:2.3.0-SNAPSHOT |
Beta Was this translation helpful? Give feedback.
-
My EJB test:
As I can't use (#1642):
Morphia morphia = new Morphia();
"Due to: ''Morphia()' has private access in 'dev.morphia.Morphia"
So tried the 'factory methods'
datastore = Morphia.createDatastore((com.mongodb.client.MongoClient) mongoClient, DATABASE);
Get:
>>>>> MorphiaMongoDBEJB init Exception = {}: java.lang.ClassCastException: class com.mongodb.MongoClient cannot be cast to class com.mongodb.client.MongoClient (com.mongodb.MongoClient and com.mongodb.client.MongoClient are in unnamed module of loader 'org.hibernate.ogm.mongodb:[email protected]' @72025f33)
Beta Was this translation helpful? Give feedback.
All reactions