JTA and Container Managed Transactions in JBoss 7.1.0
meervanderj Feb 19, 2012 4:44 AMWhen i started to develop the application i tried to use the container managed transactions using EJB3.
I am using JBoss 7.1.0 but my lazy loading is giving exceptions beacaus the Hibernate session is already closed.
In the logging i searched for the transaction statements bij there is no transaction started.
Can somebody help me what i do wrong
The error :
failed to lazily initialize a collection of role: com.narrowconnect.prototype.data.dataobjects.CategoryBean.subCategories, no session or session was closed
The logging
02:44:06,617 DEBUG [com.narrowconnect.prototype.data.facade.CategoryFacade] (http--127.0.0.1-8080-1) getAllCategories()
02:44:06,939 DEBUG [com.narrowconnect.prototype.data.dao.CategoryDAO] (http--127.0.0.1-8080-1) getAllCategories()
02:44:06,988 DEBUG [org.hibernate.internal.SessionImpl] (http--127.0.0.1-8080-1) Opened session at timestamp: 13296158469
02:44:06,989 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:06,989 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:06,990 DEBUG [org.hibernate.ejb.AbstractEntityManagerImpl] (http--127.0.0.1-8080-1) Looking for a JTA transaction to join
02:44:06,990 DEBUG [org.hibernate.ejb.AbstractEntityManagerImpl] (http--127.0.0.1-8080-1) Unable to join JTA transaction
02:44:06,990 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:06,991 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:06,992 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:06,992 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:06,995 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,000 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,001 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,001 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,001 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,001 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,010 DEBUG [org.hibernate.engine.jdbc.internal.LogicalConnectionImpl] (http--127.0.0.1-8080-1) Obtaining JDBC connection
02:44:07,013 DEBUG [org.hibernate.engine.jdbc.internal.LogicalConnectionImpl] (http--127.0.0.1-8080-1) Obtained JDBC connection
02:44:07,030 DEBUG [org.hibernate.SQL] (http--127.0.0.1-8080-1) select categorybe0_.id as id0_, categorybe0_.message as message0_, categorybe0_.shortmessage as shortmes3_0_ from Category categorybe0_
02:44:07,064 DEBUG [org.hibernate.loader.Loader] (http--127.0.0.1-8080-1) Result set row: 0
02:44:07,067 DEBUG [org.hibernate.loader.Loader] (http--127.0.0.1-8080-1) Result row: EntityKey[com.narrowconnect.prototype.data.dataobjects.CategoryBean#1]
02:44:07,067 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,068 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,071 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,071 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,072 DEBUG [org.hibernate.loader.Loader] (http--127.0.0.1-8080-1) Result set row: 1
02:44:07,072 DEBUG [org.hibernate.loader.Loader] (http--127.0.0.1-8080-1) Result row: EntityKey[com.narrowconnect.prototype.data.dataobjects.CategoryBean#2]
02:44:07,072 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,072 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,072 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,072 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,073 DEBUG [org.hibernate.loader.Loader] (http--127.0.0.1-8080-1) Result set row: 2
02:44:07,073 DEBUG [org.hibernate.loader.Loader] (http--127.0.0.1-8080-1) Result row: EntityKey[com.narrowconnect.prototype.data.dataobjects.CategoryBean#3]
02:44:07,073 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,073 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,073 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,074 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,074 DEBUG [org.hibernate.loader.Loader] (http--127.0.0.1-8080-1) Result set row: 3
02:44:07,074 DEBUG [org.hibernate.loader.Loader] (http--127.0.0.1-8080-1) Result row: EntityKey[com.narrowconnect.prototype.data.dataobjects.CategoryBean#4]
02:44:07,074 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,074 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,075 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,075 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,075 DEBUG [org.hibernate.loader.Loader] (http--127.0.0.1-8080-1) Result set row: 4
02:44:07,075 DEBUG [org.hibernate.loader.Loader] (http--127.0.0.1-8080-1) Result row: EntityKey[com.narrowconnect.prototype.data.dataobjects.CategoryBean#5]
02:44:07,075 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,075 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,076 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,076 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,076 DEBUG [org.hibernate.loader.Loader] (http--127.0.0.1-8080-1) Result set row: 5
02:44:07,076 DEBUG [org.hibernate.loader.Loader] (http--127.0.0.1-8080-1) Result row: EntityKey[com.narrowconnect.prototype.data.dataobjects.CategoryBean#6]
02:44:07,077 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,077 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,077 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,077 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,077 DEBUG [org.hibernate.loader.Loader] (http--127.0.0.1-8080-1) Result set row: 6
02:44:07,087 DEBUG [org.hibernate.engine.jdbc.internal.LogicalConnectionImpl] (http--127.0.0.1-8080-1) Releasing JDBC connection
02:44:07,087 DEBUG [org.hibernate.engine.jdbc.internal.LogicalConnectionImpl] (http--127.0.0.1-8080-1) Released JDBC connection
02:44:07,088 DEBUG [org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler] (http--127.0.0.1-8080-1) HHH000163: Logical connection releasing its physical connection
02:44:07,088 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,089 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,089 DEBUG [org.hibernate.engine.internal.TwoPhaseLoad] (http--127.0.0.1-8080-1) Resolving associations for [com.narrowconnect.prototype.data.dataobjects.CategoryBean#1]
02:44:07,090 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,090 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,094 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,094 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,095 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,095 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,096 DEBUG [org.hibernate.engine.internal.TwoPhaseLoad] (http--127.0.0.1-8080-1) Done materializing entity [com.narrowconnect.prototype.data.dataobjects.CategoryBean#1]
02:44:07,096 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,096 DEBUG [org.hibernate.engine.internal.TwoPhaseLoad] (http--127.0.0.1-8080-1) Resolving associations for [com.narrowconnect.prototype.data.dataobjects.CategoryBean#2]
02:44:07,096 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,096 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,096 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,097 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,097 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,097 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,097 DEBUG [org.hibernate.engine.internal.TwoPhaseLoad] (http--127.0.0.1-8080-1) Done materializing entity [com.narrowconnect.prototype.data.dataobjects.CategoryBean#2]
02:44:07,098 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,098 DEBUG [org.hibernate.engine.internal.TwoPhaseLoad] (http--127.0.0.1-8080-1) Resolving associations for [com.narrowconnect.prototype.data.dataobjects.CategoryBean#3]
02:44:07,098 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,098 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,098 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,098 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,099 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,099 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,099 DEBUG [org.hibernate.engine.internal.TwoPhaseLoad] (http--127.0.0.1-8080-1) Done materializing entity [com.narrowconnect.prototype.data.dataobjects.CategoryBean#3]
02:44:07,099 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,099 DEBUG [org.hibernate.engine.internal.TwoPhaseLoad] (http--127.0.0.1-8080-1) Resolving associations for [com.narrowconnect.prototype.data.dataobjects.CategoryBean#4]
02:44:07,100 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,100 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,100 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,100 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,100 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,100 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,101 DEBUG [org.hibernate.engine.internal.TwoPhaseLoad] (http--127.0.0.1-8080-1) Done materializing entity [com.narrowconnect.prototype.data.dataobjects.CategoryBean#4]
02:44:07,101 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,101 DEBUG [org.hibernate.engine.internal.TwoPhaseLoad] (http--127.0.0.1-8080-1) Resolving associations for [com.narrowconnect.prototype.data.dataobjects.CategoryBean#5]
02:44:07,101 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,101 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,101 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,102 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,102 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,102 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,102 DEBUG [org.hibernate.engine.internal.TwoPhaseLoad] (http--127.0.0.1-8080-1) Done materializing entity [com.narrowconnect.prototype.data.dataobjects.CategoryBean#5]
02:44:07,102 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,102 DEBUG [org.hibernate.engine.internal.TwoPhaseLoad] (http--127.0.0.1-8080-1) Resolving associations for [com.narrowconnect.prototype.data.dataobjects.CategoryBean#6]
02:44:07,103 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,103 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,103 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,103 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,103 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,104 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,104 DEBUG [org.hibernate.engine.internal.TwoPhaseLoad] (http--127.0.0.1-8080-1) Done materializing entity [com.narrowconnect.prototype.data.dataobjects.CategoryBean#6]
02:44:07,104 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,116 DEBUG [org.hibernate.engine.internal.StatefulPersistenceContext] (http--127.0.0.1-8080-1) Initializing non-lazy collections
02:44:07,117 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,117 DEBUG [org.hibernate.engine.jdbc.internal.LogicalConnectionImpl] (http--127.0.0.1-8080-1) Aggressively releasing JDBC connection
02:44:07,117 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,511 ERROR [com.narrowconnect.prototype.webservices.ExceptionHandling] (http--127.0.0.1-8080-1) failed to lazily initialize a collection of role: com.narrowconnect.prototype.data.dataobjects.CategoryBean.subCategories, no session or session was closed
02:44:07,643 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
02:44:07,643 DEBUG [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) Skipping JTA sync registration due to auto join checking
The code snippets :
CategoryFacade
/**
* @author jeroen
*
*/
@Stateful
@TransactionManagement(TransactionManagementType.CONTAINER)
public class CategoryFacade {
private static Logger logger = LoggerFactory
.getLogger(CategoryFacade.class);
@Inject
CategoryDAO categoryDAO;
@Inject
SubCategoryDAO subCategoryDAO;
/**
* Returns all catagories
*
* @return
*/
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public List<CategoryTO> getAllCategories() {
if (logger.isDebugEnabled()) {
logger.debug("getAllCategories()");
}
List<CategoryTO> result = CategoryTransformator
.transfromToListCategoryTO(categoryDAO.getAllCategories());
// If null result the returns an empty set
if (result == null) {
result = new ArrayList<CategoryTO>();
}
return result;
}
CategoryDAO
/**
* DAO Class for Category
*
* @author jeroen
*
*/
@Stateful(name="CategoryDAO")
@TransactionAttribute(MANDATORY)
public class CategoryDAO {
private static Logger logger = LoggerFactory.getLogger(CategoryDAO.class);
@PersistenceContext(unitName = "NarrowConnect", type=PersistenceContextType.TRANSACTION)
EntityManager entityManager;
/**
* Get all catagories
*
* @return List<CategoryTO>
*/
@SuppressWarnings("unchecked")
public List<Category> getAllCategories(){
if ( logger.isDebugEnabled() ){
logger.debug("getAllCategories()");
}
Query query = entityManager.createNamedQuery(CategoryBean.QUERY_GET_ALLCATEGORIES);
List<Category> result = (List<Category>) query.getResultList();
return result;
}
}
CategoryBean.class
@Entity
@Table(name = "Category")
@NamedQueries({
@NamedQuery(name = "getAllCategories", query = "SELECT c FROM CategoryBean c"),
@NamedQuery(name = "getMyCatagories", query = "SELECT DISTINCT s.category FROM SubCategoryBean s JOIN s.users u WHERE u.username = :userName") })
public class CategoryBean implements Serializable, Category {
public final static String QUERY_GET_ALLCATEGORIES = "getAllCategories";
public final static String QUERY_GETMYCATAGORIES = "getMyCatagories";
public final static String P_USERID = "userName";
/**
*
* VersionNumber
*
*/
private static final long serialVersionUID = 20111312112050L;
/**
* Get column ID (primary key), GeneratedValue determines that the field
* value is determined else where is will not be specificly given
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "shortmessage")
private String ShortMessage;
@Column(name = "message")
private String Message;
// bi-directional many-to-one association to SubCategory
@OneToMany(mappedBy = "category")
private List<SubCategoryBean> subCategories;