DAO と通信しているファサード (ステップと呼んでいます) を呼び出そうとするエンティティがあります。ブレークポイントを監視/設定すると、この場合のみエンティティマネージャーが null (問題のある行 >> http://goo.gl/rqyRg ) になります。正しいデバッグ方向にボールを転がすような何かをあなたの 1 人から集めたいと思っています。今のところ、問題は自分の頭蓋骨の厚さにあるのではないかと疑っています.
これが問題のファサードです。<< StepsFacade.java >>
package com.mdjdreview.session;
import com.mdjdreview.dao.Steps;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
@Stateless
public class StepsFacade extends AbstractFacade<Steps> {
@PersistenceContext(unitName = "MdJdReviewPU2")
private EntityManager em;
@Override
protected EntityManager getEntityManager() {
return em;
}
public StepsFacade() {
super(Steps.class);
}
public Object findAllRange(int low, int high) {
try {
Query q = this.em.createNamedQuery("Steps.findAllRange");
q.setMaxResults(high);
q.setFirstResult(low);
return q.getResultList();
}
catch(NoResultException ex) {
return null;
}
}
public Object findByPatternRange(String title, int low, int high) {
try {
Query q = this.em.createNamedQuery("Steps.findByPatternRange");
q.setParameter("title", title.toUpperCase() + "%");
q.setMaxResults(high);
q.setFirstResult(low);
return q.getResultList();
}
catch(NoResultException ex) {
return null;
}
}
public int findByPatternRangeCount(String title) {
Query q = this.em.createNamedQuery("Steps.findByPatternRangeCount");
q.setParameter("title", title.toUpperCase() + "%");
return ((Long) q.getSingleResult()).intValue();
}
public Object findByTitle(String title) {
try {
return this.em.createNamedQuery("Steps.findByTitle").setParameter("title", title).getSingleResult();
}
catch(NoResultException ex) {
return null;
}
}
public Object findByProductId(Object productId) {
try {
return this.em.createNamedQuery("Steps.findByProductId").setParameter("productId", productId).getResultList();
} catch (Exception e) {
System.out.println("----------- findByProductId err "+e.getLocalizedMessage());
System.out.println("----------- findByProductId err "+e.getMessage());
System.out.println("----------- findByProductId err "+e.getStackTrace());
System.out.println(productId);
return e.getMessage();
}
}
public int findByProductQuestionCount(Object productId) {
Query q = this.em.createNamedQuery("Steps.findByProductQuestionCount");
q.setParameter("productId", productId);
if(q.getSingleResult() == null) {
return 0;
}
else {
return ((Long) q.getSingleResult()).intValue();
}
}
public int findBySlideStepCount(Object slidesId) {
Query q = this.em.createNamedQuery("Steps.findBySlideStepCount");
q.setParameter("slidesId", slidesId);
if(q.getSingleResult() == null) {
return 0;
}
else {
return ((Long) q.getSingleResult()).intValue();
}
}
public int findByCategoryStepCount(Object categoriesId) {
Query q = this.em.createNamedQuery("Steps.findByCategoryStepCount");
q.setParameter("categoriesId", categoriesId);
if(q.getSingleResult() == null) {
return 0;
}
else {
return ((Long) q.getSingleResult()).intValue();
}
}
public int findByModuleStepCount(Object modulesId) {
Query q = this.em.createNamedQuery("Steps.findByModuleStepCount");
q.setParameter("modulesId", modulesId);
if(q.getSingleResult() == null) {
return 0;
}
else {
return ((Long) q.getSingleResult()).intValue();
}
}
public Object findByExamStep(Object step, Object generatedExamsId) {
try {
Query q = this.em.createNamedQuery("Steps.findByExamStep");
q.setParameter("step", step);
q.setParameter("generatedExamsId", generatedExamsId);
q.setMaxResults(1);
q.setFirstResult(0);
return q.getSingleResult();
}
catch(NoResultException ex) {
return null;
}
}
/**
* @param em the em to set
*/
public void setEntityManager(EntityManager em) {
this.em = em;
}
}
そして、非常に不可解なのは、ほぼ同じコードでうまく機能する Facade がここにあるということです。<< AnswersFacade.java >>
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.mdjdreview.session;
import com.mdjdreview.dao.Answers;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
/**
*
* @author nick
*/
@Stateless
public class AnswersFacade extends AbstractFacade<Answers> {
@PersistenceContext(unitName = "MdJdReviewPU2")
private EntityManager em;
@Override
protected EntityManager getEntityManager() {
return em;
}
public AnswersFacade() {
super(Answers.class);
}
public Object findByQuestionId(Object questionId) {
try {
return this.em.createNamedQuery("Answers.findByQuestionId").setParameter("questionId", questionId).getResultList();
}
catch(NoResultException ex) {
return null;
}
}
public Object findAllRange(int low, int high) {
try {
Query q = this.em.createNamedQuery("Answers.findAllRange");
q.setMaxResults(high);
q.setFirstResult(low);
return q.getResultList();
}
catch(NoResultException ex) {
return null;
}
}
public Object findByPatternRange(String title, int low, int high) {
try {
Query q = this.em.createNamedQuery("Answers.findByPatternRange");
q.setParameter("title", title.toUpperCase() + "%");
q.setMaxResults(high);
q.setFirstResult(low);
return q.getResultList();
}
catch(NoResultException ex) {
return null;
}
}
public int findByPatternRangeCount(String title) {
Query q = this.em.createNamedQuery("Answers.findByPatternRangeCount");
q.setParameter("title", title.toUpperCase() + "%");
return ((Long) q.getSingleResult()).intValue();
}
}
Facade を呼び出しているエンティティ << ExamResults.java >>
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.mdjdreview.entities;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import org.primefaces.model.chart.CartesianChartModel;
import org.primefaces.model.chart.ChartSeries;
import org.primefaces.model.chart.PieChartModel;
// I need to import this package to allow for access to the category object
import com.mdjdreview.dao.Steps;
import com.mdjdreview.dao.Categories;
import com.mdjdreview.session.StepsFacade;
import com.mdjdreview.session.CategoriesFacade;
import com.mdjdreview.session.ProductToCategoriesFacade;
import com.mdjdreview.session.ProductToStepsFacade;
import java.util.List;
import java.util.Map;
import javax.ejb.EJB;
/**
*
* @author joshua
* this is where we layout the graph
*
*/
@ManagedBean
@ViewScoped
public class ExamResults implements Serializable {
private CartesianChartModel categoryModel;
private PieChartModel pieModel;
@EJB
private StepsFacade stepsFacade = new StepsFacade();
@EJB
private CategoriesFacade categoryFacade = new CategoriesFacade();
public ExamResults() {
createCategoryModel();
}
public CartesianChartModel getCategoryModel() {
return categoryModel;
}
public PieChartModel getPieModel() {
return pieModel;
}
// this one draws out the graph
private void createCategoryModel() {
categoryModel = new CartesianChartModel();
Map requestMap = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
// TODO: this is not called eamxId, this is a productId don't forget to change this
String productId = (String) requestMap.get("productId");
System.out.println("--------------------------- prouctID = "+productId);
List<Categories> cats;
List<Steps> steps;
try {
steps = (List<Steps>)this.stepsFacade.findByProductId((Object)productId);
int itemCount = steps.size();
System.out.println("setps in list = "+itemCount);
} catch (Exception e) {
System.out.println("no steps for you");
System.out.println(e.getMessage());
}
try {
cats = this.categoryFacade.findByTypeParentId((Object)productId, "question");
int itemCount = cats.size();
System.out.println("cats in list = "+itemCount);
} catch (Exception e) {
System.out.println("no, dice on the categories");
}
//
System.out.println("just tried to pull steps what's above this line?");
ChartSeries correct = new ChartSeries();
correct.setLabel("Correct");
// what they got right
// setp 1:
// <LIST> Step pull back by the steps facade
// <LIST> Keywords
// <LIST> Catnames
// step 2: loop through steps, query category ID
// that 90 there for heart is a magic number, that needs to be pulled in dynamically
// it looks lie in the AnswersToCategories dao, we can pull the
correct.set("Heart", 90);
correct.set("Bacteria", 100);
correct.set("Mitral Valve", 44);
correct.set("Pediatrics", 80);
correct.set("OBGYN", 25);
ChartSeries missed = new ChartSeries();
missed.setLabel("Missed");
// what they got wrong
missed.set("Heart", 10);
missed.set("Bacteria", 0);
missed.set("Mitral Valve", 56);
missed.set("Pediatrics", 20);
missed.set("OBGYN", 75);
// auto create x & y
categoryModel.addSeries(correct);
categoryModel.addSeries(missed);
}
}
これまでに修正しようとしたことは次のとおりです。
- アプリケーション サーバー (GlassFish) の起動出力を調べましたが、そこには何も表示されませんでした。誰もが満足しており、警告もエラーもそれ以上のものもありません。情報がたくさんあるだけです。
- 私はスタックオーバーフロー全体を見てきましたが、多くのコードはこれと同じように見え、手がかりを怖がらせることができませんでした.
- 私のエンティティから、Facades ( http://goo.gl/MSl8F ) が注入され、新しい Facade オブジェクトをインスタンス化しないことを望んでいることを期待していました (以下)。ブレークポイント)。
@EJB private StepsFacade stepsFacade; @EJB private CategoriesFacade categoryFacade;
何か案は?ご覧いただきありがとうございます。