为了保持简短,注入的DAO为空。这是代码:
IssueBeanLocal用@Local注释,持久性单元名称是name =" fmiunibuc"
@Stateless
public class IssueBean implements IssueBeanLocal{
@Inject IssueDAO issueDAO;
@Override
public List<Object[]> loadDDL(String table) {
return issueDAO.getDDL(table);
}
}
DAO:
public class IssueDAO extends GenericDAO {
public Issue getById(Long id) {
Issue issue = findById(id, Issue.class);
if (issue == null) {
throw new IllegalArgumentException("No theme design validation exists with ID [" + id + "].");
}
return issue;
}
public List<Object[]> getDDL(String tableName) {
List<Object[]> returnList = new ArrayList<Object[]>();
StringBuilder dynamicQuery = new StringBuilder();
dynamicQuery.append(" SELECT cat.id ");
dynamicQuery.append(", cat.code + ' ' + cat.name as ddlValue");
dynamicQuery.append(" FROM ").append(tableName + " as cat ");
dynamicQuery.append(" WHERE cat.active = true");
dynamicQuery.append(" order by cat.code");
returnList = entityManager.createQuery(dynamicQuery.toString(), Object[].class).getResultList();
//returnList
return returnList;
}
GenericDAO:
public abstract class GenericDAO {
@PersistenceContext(unitName="fmiunibuc", type=PersistenceContextType.TRANSACTION)
protected EntityManager entityManager;
protected static Logger logger;
public GenericDAO() {
logger = LoggerFactory.getLogger(this.getClass());
}
public <T> void persist(T entity) {
entityManager.persist(entity);
}
// some other methods
}
当执行到达&#34; issueDAO.getDDL(table);&#34; issueDAO为空。 请记住,我是java编程的新手,所以请尽可能明确。 感谢