私は Broadleaf を初めて使用し、フレームワークに慣れるために Broadleaf Demo プロジェクトに時間を費やしてきました。私は現在の安定した Broadleaf バージョン - v2.2 を使用しています。
私の目的は、管理コンソールを使用せずに動的なカテゴリ/製品を作成することです。ただし、TransientObjectExceptionを取得しています:
java.lang.IllegalStateException: org.hibernate.TransientObjectException: object is an unsaved transient instance - save the transient instance before merging: org.broadleafcommerce.core.catalog.domain.CategoryImpl
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1386)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1317)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1323)
これは、カテゴリ/製品を作成しようとしている方法です:
private void addProductMetaData(Product product) {
product.setName("phone A");
product.setFeaturedProduct(true);
product.setUrl("/phones/phoneA");
product.setCanSellWithoutOptions(true);
product.setManufacturer("manufacturer A");
product.setActiveStartDate(new Date());
product.setActiveEndDate(null);
addMediaInformation(product);
Category category = retrieveCategory();
product.setDefaultCategory(category);
// product.getAllParentCategories().add(category);
catalogService.saveProduct(product); //**Exception occurs here**
}
private Category retrieveCategory() {
List<Category> categories = catalogService.findCategoriesByName("phones");
Category category = (CollectionUtils.isEmpty(categories) ? catalogService.createCategory() : categories.get(0));
if (StringUtils.isEmpty(category.getName())) {
category.setName("phones");
category.setUrl("/phones");
Category parentCategory = catalogService.findCategoriesByName("Primary Nav").get(0);
category.setDefaultParentCategory(parentCategory);
category.setActiveStartDate(new Date());
category.getAllParentCategories().add(parentCategory);
catalogService.saveCategory(category);
}
return category;
}
この例外が発生する理由(カテゴリが永続化されているため)と、それを解決するにはどうすればよいかを誰かが説明できますか?