@ Override @ PortalTransactional public IMarketplaceRating createOrUpdateRating ( IMarketplaceRating marketplaceRatingImplementation ) { Validate . notNull ( marketplaceRatingImplementation , "MarketplaceRatingImpl must not be null" ) ; final EntityManager entityManager = this . getEntityManager ( ) ; IMarketplaceRating temp = this . getRating ( marketplaceRatingImplementation . getMarketplaceRatingPK ( ) ) ; if ( ! entityManager . contains ( marketplaceRatingImplementation ) && temp != null ) { // Entity is not managed and there is a rating for this portlet/user - update needed temp = entityManager . merge ( marketplaceRatingImplementation ) ; } else { // Entity is either already managed or doesn't exist - create needed temp = marketplaceRatingImplementation ; } entityManager . persist ( temp ) ; return temp ; }
This method will either create a new rating or update an existing rating