Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. javax.persistence.TransactionRequiredException: No active transaction for PuId=...
  2.  
  3. <?xml version="1.0" encoding="UTF-8"?>
  4. <persistence version="2.0"
  5. xmlns="http://java.sun.com/xml/ns/persistence"
  6. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  7. xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  8.  
  9. <persistence-unit name="hcms" transaction-type="JTA">
  10. <jta-data-source>jdbc/hcms</jta-data-source>
  11. </persistence-unit>
  12. </persistence>
  13.  
  14. @Stateless
  15. public class CommunityAddressDao extends Dao<CommunityAddressEntity, Integer> {
  16. @PersistenceContext(unitName="hcms")
  17. private EntityManager em;
  18.  
  19. ...
  20.  
  21. }
  22.  
  23. @Stateless
  24. @Path("/addresses")
  25. @Produces(MediaType.APPLICATION_JSON)
  26. @RolesAllowed({"user"})
  27. public class CommunityAddressService {
  28. @Inject
  29. private CommunityAddressDao addressDao;
  30.  
  31. ...
  32.  
  33. @POST
  34. @Consumes(MediaType.APPLICATION_JSON)
  35. public CommunityAddressDto registerAddress(CommunityAddressDto address) throws DuplicateAddressException, ManagedAddressException, BadRequestException {
  36. // Validation
  37.  
  38. CommunityAddressEntity entity = new CommunityAddressEntity();
  39. entity.setCommunityUuid(address.getCommunityUuid());
  40. ...
  41.  
  42. addressDao.persist(entity);
  43.  
  44. return new CommunityAddressDto(entity);
  45. }
  46. }
  47.  
  48. @ViewScoped
  49. @Named("addressBean")
  50. public class CommunityAddressBean implements Serializable {
  51. private static final long serialVersionUID = -1685666287294618708L;
  52.  
  53. @Inject
  54. private CommunityAddressDao addressDao;
  55.  
  56. private List<CommunityAddressEntity> addresses;
  57.  
  58. ...
  59.  
  60. @PostConstruct
  61. private void init() {
  62. // Retrieve first 10 addresses - Works fine
  63. addresses = addressDao.findAll(10, 0);
  64. }
  65.  
  66. public void createAddress() {
  67. CommunityAddressEntity entity = new CommunityAddressEntity();
  68. entity.setCommunityUuid("some UUID");
  69. ...
  70.  
  71. // Throws javax.persistence.TransactionRequiredException: No active transaction for PuId=...
  72. addressDao.persist(entity);
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement