I don't know how to relate this bug to jboss please anyone relate this it's a very worst bug.
In Jboss 7.x or after versions like jboss eap 6.2.0 i found this bug, @TransactionAttribute(TransactionAttributeType.SUPPORTS) at class level,
makes the container ignore a method declaration of @TransactionAttribute(TransactionAttributeType.REQUIRED) and throw javax.persistence.TransactionRequiredException
Other way to avoid javax.persistence.TransactionRequiredException in bugged versions of jboss is using a interface without generics
In jboss 6 versions @TransactionAttribute(TransactionAttributeType.SUPPORTS) at class level works as ejb-spec.
Example:
@Stateless @Local(BO.class) @TransactionManagement(TransactionManagementType.CONTAINER) @TransactionAttribute(TransactionAttributeType.SUPPORTS) public class BOImpl implements BO { @PersistenceContext(unitName = "sgenEjbTestPU") private EntityManager em; @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public AppParam saveOrUpdate(AppParam param) { em.persist(param); return param; } } import br.com.pegasus.sgen.domain.AppParam; public interface BO extends BOIFGeneric<AppParam, Integer> { } public interface BOIFGeneric<T, Id> { T saveOrUpdate(T param); } import br.com.pegasus.sgen.domain.AppParam; public interface BOIFWithoutGenerics { AppParam saveOrUpdate(AppParam param); } @Entity @Table(name = "tb_app_param") @XmlRootElement public class AppParam implements Serializable { private static final long serialVersionUID = 4818981684503640410L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @Column(name = "id_app_param") private Integer id; @Basic(optional = false) @Column(name = "name") private String name; @Basic(optional = false) @Column(name = "js_value") private String jsValue; public AppParam() { } public AppParam(Integer id) { this.id = id; } public AppParam(String name) { this.name = name; } public AppParam(Integer id, String name, String jsValue) { this.id = id; this.name = name; this.jsValue = jsValue; } public Integer getId() { return this.id; } public void setId(Integer id) { this.id = id; } public String getName() { return this.name; } public void setName(String name) { this.name = name; } public String getJsValue() { return this.jsValue; } public void setJsValue(String jsValue) { this.jsValue = jsValue; } public int hashCode() { int hash = 0; hash += (this.id != null ? this.id.hashCode() : 0); return hash; } public boolean equals(Object object) { if (!(object instanceof AppParam)) { return false; } AppParam other = (AppParam) object; if (((this.id == null) && (other.id != null)) || ((this.id != null) && (!this.id.equals(other.id)))) { return false; } return true; } }
in persistence.xml <persistence-unit name="sgenEjbTestPU" transaction-type="JTA"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:/sgenXAMysqlDS</jta-data-source> <jar-file>lib/sgen-domain-1.0.0.jar</jar-file> <properties> <property name="hibernate.show_sql" value="true" /> <property name="hibernate.format_sql" value="true" /> <property name="hibernate.use_sql_comments" value="false" /> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect" /> </properties> </persistence-unit>
in com/mysql/main/modules.xml <?xml version="1.0" encoding="UTF-8"?> <module xmlns="urn:jboss:module:1.0" name="com.mysql"> <resources> <resource-root path="mysql-connector-java-5.1.22-bin.jar"/> </resources> <dependencies> <module name="javax.api"/> <module name="javax.transaction.api"/> </dependencies> </module>
About me i'm a SCJP 6, SCWD 5 and OCPBCD 5 and 6 years working with Java, this is not my code error, it's a bug of jboss.
Comments