【发布时间】:2015-09-15 08:09:01
【问题描述】:
我是 broadleaf 应用程序的新手。我能够很好地使用 tomcat + mysql 集成运行应用程序。现在我想继续开发以根据我的要求自定义站点项目。
我在阔叶网站模块中坚持不懈。我尝试使用em.merge 返回我的实体,但不将其保存在数据库中,也尝试使用@Transactional(value="blTransactionManager"),但问题仍然存在。我在 applicationContext-servlet.xml
<aop:config>
<aop:pointcut id="blMyStoreDao" expression="execution(* com.mycompany.dao.StoreDaoImpl.save*(..))"/>
<aop:advisor advice-ref="blTxAdvice" pointcut-ref="blMyStoreDao"/>
</aop:config>
这是我的控制器代码
newStore.setCustomer(customer);
newStore.setProductList(new ArrayList<ProductImpl>());
Store getStore=store.save(em, newStore);
System.out.println(getStore.getCustomer().getUsername());
System.out.println("customer fetched: "+customer.getEmailAddress());
这是我的 daoimpl 代码
@Repository("blMyStoreDao")
@Transactional(value="blTransactionManager")
public class StoreDaoImpl implements StoreDao {
@PersistenceContext(unitName="blPU")
protected EntityManager em;
@Transactional(value="blTransactionManager")
public Store save(EntityManager em, Store store) {
System.out.println(em);
System.out.println(store.getCustomer().getUsername());
Store s= em.merge(store);
return s;
}
}
但这也没有解决我的问题。
代码按应有的方式完美运行,但它没有将我的实体保存在数据库中。
任何人都可以帮助。提前致谢
【问题讨论】:
-
你可以在 StoreDaoImpl 中的 em.merge(store) 之后尝试 em.flush() 并发布异常
-
你到底为什么要传入
EntityManager?您应该使用 dao 中的EntityManager实例,而不是您传入的实例。接下来您有@Transactional,因此请确保您的配置中有<tx:annotation-driven />。 -
我也做了同样的事情,但它没有在 daoimpl 中注入 em。另一件事是关于@transsection。其中
标签: mysql spring hibernate jpa broadleaf-commerce