JBoss WildFly 11、Hibernate ORM 5.2、OGM 5.3 和 MongoDB - 零长度的对



我有一个MongoDB集合和文档,其中包含一个嵌入的对象数组:"qtyContent"。填充了 PoC 的测试字符串数据:

id:5aa2c7b4aaa32bcb1d7cfc93 ean: "05052319711639" qty内容 : 数组 0 : 对象数量 : "1.1" 总计数量 : "1.2" 数量Uom : "1.3" 净内容 : "1.4" 平均度量 : "1.5" 1 : 对象数量 : "2.1" 总数量 : "2.2" 数量Uom : "2.3" 净内容 : "2.4" 平均测量 : "2.5">

我的实体是:

@Entity
@Indexed
@Table(name = "foodsCosmeticsMedicines")
public class FoodsCosmeticsMedicines implements Serializable {
@ElementCollection
private List<QtyContents> qtyContentsList;
//setters & getters
}

对于"数量内容":

@Embeddable
public class QtyContents implements Serializable {
private String quantity;
private String totalQuantity;
private String quantityUom;
private String netContents;
private String avgMeasure;
//setters & getters
}

当我运行我的单元测试时,我得到:

09:44:18,762 信息 [com.notifywell.controller.NOTiFYwellController] (默认任务-56)>>>>> NOTiFYwellController 得到所有食品化妆品药品JES.....09:44:18,764 信息 [com.notifywell.ejb.FoodsCosmeticsMedicinesEJB](默认任务-56)

getAllFoodsCosmeticsMedicinesJSON = 09:44:18,770 INFO [com.notifywell.ejb.FoodsCosmeticsMedicinesEJB](默认任务-56) getAllFoodsCosmeticsMedicinesJSON foods化妆品药品列表 = 1 09:44:18,770 INFO [com.notifywell.ejb.FoodsCosmeticsMedicinesEJB] (默认任务-56)>>>>> getAllFoodsCosmeticsMedicinesJSON id = 5aa2c7b4aaa32bcb1d7cfc93 09:44:18,770 信息 [com.notifywell.ejb.FoodsCosmeticsMedicinesEJB](默认任务-56) getAllFoodsCosmeticsMedicinesJSON ean = 05052319711639 09:44:18,771 INFO [com.notifywell.ejb.FoodsCosmeticsMedicinesEJB] (默认任务-56)>>>>>获取全部食品化妆品药品JSON说明 = 09:44:18,771 INFO [com.notifywell.ejb.FoodsCosmeticsMedicinesEJB](默认任务-56)>>>>> getAllFoodsCosmeticsMedicinesJSON qtyContents = 0 09:44:18,802 INFO [com.notifywell.ejb.FoodsCosmeticsMedicinesEJB] (默认任务-56) [ { "id": "5aa2c7b4aaa32bcb1d7cfc93", "ean": "05052319711639", "描述": " } ]

我得到一个"食品化妆品药品"系列:

09:44:18,770 信息 [com.notifywell.ejb.FoodsCosmeticsMedicinesEJB](默认任务-56)>>>>> getAllFoodsCosmeticsMedicinesJSON foods化妆品药品列表 = 1

但是"qtyContent"数组是空的。

09:44:18,771 信息 [com.notifywell.ejb.FoodsCosmeticsMedicinesEJB] (默认任务-56)>>>>> getAllFoodsCosmeticsMedicinesJSON qtyContents = 0

它应该有两个文件。

知道我对数组/集合的注释做错了什么吗?

单元测试(使用 HTTP GET)调用作为 Web 服务公开的控制器(@model注释的 POJO)中的方法。

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/get-foods-cosmetics-medicines")

控制器使用 CDI 将 EJB @inject到其中。控制器调用注入的 EJB 中的一个方法,该方法查询 MongoDB 数据库和集合,并以 JSON 形式返回结果。使用记录器打印我的嵌入实体的值。

EJB 方法:

/**
* @return String
*/
public String getAllFoodsCosmeticsMedicinesJSON() {
logger.info(">>>>> getAllFoodsCosmeticsMedicinesJSON = ");
Query query = entityManager.createQuery("FROM FoodsCosmeticsMedicines f");
List<com.notifywell.entity.FoodsCosmeticsMedicines> foodsCosmeticsMedicinesList = query.getResultList();
logger.info(">>>>> getAllFoodsCosmeticsMedicinesJSON foodsCosmeticsMedicinesList = " + foodsCosmeticsMedicinesList.size());
for (FoodsCosmeticsMedicines foodsCosmeticsMedicines : foodsCosmeticsMedicinesList) {
logger.info(">>>>> getAllFoodsCosmeticsMedicinesJSON id = " + foodsCosmeticsMedicines.getId());
logger.info(">>>>> getAllFoodsCosmeticsMedicinesJSON ean = " + foodsCosmeticsMedicines.getEan());
logger.info(">>>>> getAllFoodsCosmeticsMedicinesJSON description = " + foodsCosmeticsMedicines.getDescription());
logger.info(">>>>> getAllFoodsCosmeticsMedicinesJSON getQtyContentsList = " + foodsCosmeticsMedicines.getQtyContentsList());
logger.info(">>>>> getAllFoodsCosmeticsMedicinesJSON getProductCharacteristics getProductCharacteristics = " + foodsCosmeticsMedicines.getProductCharacteristics().getIsFood());
logger.info(">>>>> getAllFoodsCosmeticsMedicinesJSON getLifestyle getLifestyle = " + foodsCosmeticsMedicines.getLifestyle().getName());
}
Gson gson = getGsonBuilder().create();
// deserialize
String json = gson.toJson(foodsCosmeticsMedicinesList);
logger.info(json);
return json;
}

我的坚持.xml

<persistence-unit name="nOTiFYwellMongoDBPersistenceUnit" transaction-type="JTA">
<provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
<properties>
<property name="jboss.as.jpa.providerModule" value="org.hibernate:5.2"/>
<property name="wildfly.jpa.hibernate.search.module" value="org.hibernate.search.orm:5.8"/>
<!-- <property name="hibernate.transaction.jta.platform" value="JBossTS"/> -->
<!-- <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAS"/> -->
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform"/>
<property name="hibernate.ogm.datastore.provider" value="org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider"/>
<property name="hibernate.ogm.datastore.grid_dialect" value="org.hibernate.ogm.datastore.mongodb.MongoDBDialect"/>
<property name="hibernate.ogm.datastore.database" value="notifyWellDB"/>
<property name="hibernate.ogm.mongodb.host" value="127.0.0.1"/>
</properties>
</persistence-unit>

输出:

22:

25:36,538 INFO [com.notifywell.controller.NOTiFYwellController] (默认任务-4)>>>>> NOTiFYwellController 得到所有食品化妆品药品JES.....22:25:36,541 信息 [com.notifywell.ejb.FoodsCosmeticsMedicinesEJB] (默认任务-4)>>>>>getAllFoodsCosmeticsMedicinesJSON = 22:25:36,551 INFO [com.notifywell.ejb.FoodsCosmeticsMedicinesEJB] (默认任务-4)>>>>>getAllFoodsCosmeticsMedicinesJSON foodsCosmeticsMedicinesList = 1 22:25:36,551 信息 [com.notifywell.ejb.FoodsCosmeticsMedicinesEJB] (默认任务 4)>>>>>获取所有食品化妆品药品JSON ID = 5aa6bc4340cf3a7178094a8f 22:25:36,551 信息 [com.notifywell.ejb.FoodsCosmeticsMedicinesEJB] (默认任务-4)>>>>>getAllFoodsCosmeticsMedicinesJSON ean = 05052319711639 22:25:36,551 INFO [com.notifywell.ejb.FoodsCosmeticsMedicinesEJB](默认任务-4)

getAllFoodsCosmeticsMedicinesJSON 描述 = 22:25:36,551 INFO [com.notifywell.ejb.FoodsCosmeticsMedicinesEJB](默认任务-4)>>>>> getAllFoodsCosmeticsMedicinesJSON getQtyContentList =[] 22:25:36,552 INFO [com.notifywell.ejb.FoodsCosmeticsMedicinesEJB] (默认任务 4)>>>>>获取全部食品化妆品药品JSON 获取产品特征 获取产品特征 = 22:25:36,552 INFO [com.notifywell.ejb.FoodsCosmeticsMedicinesEJB](默认任务-4) getAllFoods化妆品药品JSON get生活方式 getLifestyle = 生活方式 22:25:36,586 信息 [com.notifywell.ejb.FoodsCosmeticsMedicinesEJB](默认任务-4)[ { "id": "5aa6bc4340cf3a7178094a8f", "ean": "05052319711639", "描述": " } ]

您可以看到粗体行显示空数组。

最新更新