Jakarta ee CDI@Tansactional不适用于JAX-RS类
我有这样的方法:Jakarta ee CDI@Tansactional不适用于JAX-RS类,jakarta-ee,ejb,jax-rs,cdi,transactional,Jakarta Ee,Ejb,Jax Rs,Cdi,Transactional,我有这样的方法: @Transactional @PUT @Path("/{servicePointNumber : \\d+}") @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public Response updateServicePoint( @PathParam("userId") Long userId,
@Transactional
@PUT
@Path("/{servicePointNumber : \\d+}")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public Response updateServicePoint( @PathParam("userId") Long userId,
@PathParam("servicePointNumber") Integer servicePointNumber,
ServicePoint servicePoint,
@BeanParam GenericBeanParam params) throws ForbiddenException, UnprocessableEntityException, InternalServerErrorException {
if(params.getAuthToken() == null) throw new ForbiddenException("Unauthorized access to web service.");
logger.log(Level.INFO, "updating existing Service Point by executing ProviderResource.ServicePointResource.updateServicePoint(servicePoint) method of REST API");
// set resource ID passed in path param on updated resource object
Provider foundProvider = providerFacade.find(userId);
servicePoint.setProvider(foundProvider);
servicePoint.setServicePointNumber(servicePointNumber);
ServicePoint updatedServicePoint = null;
try {
// reflect updated resource object in database
updatedServicePoint = servicePointFacade.update(servicePoint);
// populate created resource with hypermedia links
pl.salonea.jaxrs.ServicePointResource.populateWithHATEOASLinks(updatedServicePoint, params.getUriInfo());
} catch (EJBTransactionRolledbackException ex) {
ExceptionHandler.handleEJBTransactionRolledbackException(ex);
} catch (EJBException ex) {
ExceptionHandler.handleEJBException(ex);
} catch(Exception ex) {
throw new InternalServerErrorException(ExceptionHandler.ENTITY_UPDATE_ERROR_MESSAGE);
}
return Response.status(Status.OK).entity(updatedServicePoint).build();
}
这个方法是在JAX-RS层的ServicePointResource类中定义的。这是ProviderResource类的内部类。
这里的问题是代码引发异常:
Transaction aimed at persisting entity instance has been rolled back: detached entity passed to persist: pl.salonea.entities.Provider
Provider是与ServicePoint的@ManyTone关联,而且Provider ID是ServicePoint复合主键的一部分
如果我动议这部分:
// set resource ID passed in path param on updated resource object
Provider foundProvider = providerFacade.find(userId);
servicePoint.setProvider(foundProvider);
servicePoint.setServicePointNumber(servicePointNumber);
ServicePoint updatedServicePoint = null;
try {
// reflect updated resource object in database
updatedServicePoint = servicePointFacade.update(servicePoint);
对于外部EJB类,它是@Stateless session bean,并且具有所需类型的默认事务管理,这将正确更新,并且不会出现detach方法错误。因此,我认为上述方法的@Transactional注释划分没有效果,也不起作用 providerFacade看起来像什么?它是如何在这里实例化的?它是作为\@无状态EJB实现的DAO,并使用\@注入进行注入