Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- javax.persistence.TransactionRequiredException: No active transaction for PuId=...
- <?xml version="1.0" encoding="UTF-8"?>
- <persistence version="2.0"
- xmlns="http://java.sun.com/xml/ns/persistence"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
- <persistence-unit name="hcms" transaction-type="JTA">
- <jta-data-source>jdbc/hcms</jta-data-source>
- </persistence-unit>
- </persistence>
- @Stateless
- public class CommunityAddressDao extends Dao<CommunityAddressEntity, Integer> {
- @PersistenceContext(unitName="hcms")
- private EntityManager em;
- ...
- }
- @Stateless
- @Path("/addresses")
- @Produces(MediaType.APPLICATION_JSON)
- @RolesAllowed({"user"})
- public class CommunityAddressService {
- @Inject
- private CommunityAddressDao addressDao;
- ...
- @POST
- @Consumes(MediaType.APPLICATION_JSON)
- public CommunityAddressDto registerAddress(CommunityAddressDto address) throws DuplicateAddressException, ManagedAddressException, BadRequestException {
- // Validation
- CommunityAddressEntity entity = new CommunityAddressEntity();
- entity.setCommunityUuid(address.getCommunityUuid());
- ...
- addressDao.persist(entity);
- return new CommunityAddressDto(entity);
- }
- }
- @ViewScoped
- @Named("addressBean")
- public class CommunityAddressBean implements Serializable {
- private static final long serialVersionUID = -1685666287294618708L;
- @Inject
- private CommunityAddressDao addressDao;
- private List<CommunityAddressEntity> addresses;
- ...
- @PostConstruct
- private void init() {
- // Retrieve first 10 addresses - Works fine
- addresses = addressDao.findAll(10, 0);
- }
- public void createAddress() {
- CommunityAddressEntity entity = new CommunityAddressEntity();
- entity.setCommunityUuid("some UUID");
- ...
- // Throws javax.persistence.TransactionRequiredException: No active transaction for PuId=...
- addressDao.persist(entity);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement