Auto Generated Code for Using Persistence Not Compiling
I am new to JSF development and was trying to complete the Using Java Persistence in J2EE 1.4 Web Application tutorial. Since I have an existing database, instead of creating a new entity class, I used the create entity class from DB option. I then followed the steps for creating a web interface. When I try to complile the code, I get the following errors. Is there an additional library that I need to include or did I miss a step? Any help would be greatly appreciated.
init:
deps-module-jar:
deps-ear-jar:
deps-jar:
library-inclusion-in-archive:
library-inclusion-in-manifest:
Compiling 11 source files to C:\Documents and Settings\homi1\My Documents\NetBeansProjects\DBVersionUpdate\build\web\WEB-INF\classes
C:\Documents and Settings\homi1\My Documents\NetBeansProjects\DBVersionUpdate\src\java\dbversionupdate\MaturityCodesController.java:285: incompatible types
found : java.lang.Object
required: java.lang.String
return FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(key);
C:\Documents and Settings\homi1\My Documents\NetBeansProjects\DBVersionUpdate\src\java\dbversionupdate\MaturityCodesController.java:399: cannot find symbol
symbol : method getELContext()
location: class javax.faces.context.FacesContext
Object relatedController = context.getApplication().getELResolver().getValue(context.getELContext(), null, relatedControllerString);
C:\Documents and Settings\homi1\My Documents\NetBeansProjects\DBVersionUpdate\src\java\dbversionupdate\MaturityCodesController.java:399: cannot find symbol
symbol : method getELResolver()
location: class javax.faces.application.Application
Object relatedController = context.getApplication().getELResolver().getValue(context.getELContext(), null, relatedControllerString);
C:\Documents and Settings\homi1\My Documents\NetBeansProjects\DBVersionUpdate\src\java\dbversionupdate\MaturityCodesConverter.java:23: cannot find symbol
symbol : method getELContext()
location: class javax.faces.context.FacesContext
MaturityCodesController controller = (MaturityCodesController) facesContext.getApplication().getELResolver().getValue(facesContext.getELContext(), null, "maturityCodes");
C:\Documents and Settings\homi1\My Documents\NetBeansProjects\DBVersionUpdate\src\java\dbversionupdate\MaturityCodesConverter.java:23: cannot find symbol
symbol : method getELResolver()
location: class javax.faces.application.Application
MaturityCodesController controller = (MaturityCodesController) facesContext.getApplication().getELResolver().getValue(facesContext.getELContext(), null, "maturityCodes");
C:\Documents and Settings\homi1\My Documents\NetBeansProjects\DBVersionUpdate\src\java\dbversionupdate\ProductsController.java:285: incompatible types
found : java.lang.Object
required: java.lang.String
return FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(key);
C:\Documents and Settings\homi1\My Documents\NetBeansProjects\DBVersionUpdate\src\java\dbversionupdate\ProductsController.java:398: cannot find symbol
symbol : method getELContext()
location: class javax.faces.context.FacesContext
Object relatedController = context.getApplication().getELResolver().getValue(context.getELContext(), null, relatedControllerString);
C:\Documents and Settings\homi1\My Documents\NetBeansProjects\DBVersionUpdate\src\java\dbversionupdate\ProductsController.java:398: cannot find symbol
symbol : method getELResolver()
location: class javax.faces.application.Application
Object relatedController = context.getApplication().getELResolver().getValue(context.getELContext(), null, relatedControllerString);
C:\Documents and Settings\homi1\My Documents\NetBeansProjects\DBVersionUpdate\src\java\dbversionupdate\ProductsConverter.java:23: cannot find symbol
symbol : method getELContext()
location: class javax.faces.context.FacesContext
ProductsController controller = (ProductsController) facesContext.getApplication().getELResolver().getValue(facesContext.getELContext(), null, "products");
C:\Documents and Settings\homi1\My Documents\NetBeansProjects\DBVersionUpdate\src\java\dbversionupdate\ProductsConverter.java:23: cannot find symbol
symbol : method getELResolver()
location: class javax.faces.application.Application
ProductsController controller = (ProductsController) facesContext.getApplication().getELResolver().getValue(facesContext.getELContext(), null, "products");
C:\Documents and Settings\homi1\My Documents\NetBeansProjects\DBVersionUpdate\src\java\dbversionupdate\SubversionsController.java:331: incompatible types
found : java.lang.Object
required: java.lang.String
return FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(key);
C:\Documents and Settings\homi1\My Documents\NetBeansProjects\DBVersionUpdate\src\java\dbversionupdate\SubversionsController.java:444: cannot find symbol
symbol : method getELContext()
location: class javax.faces.context.FacesContext
Object relatedController = context.getApplication().getELResolver().getValue(context.getELContext(), null, relatedControllerString);
C:\Documents and Settings\homi1\My Documents\NetBeansProjects\DBVersionUpdate\src\java\dbversionupdate\SubversionsController.java:444: cannot find symbol
symbol : method getELResolver()
location: class javax.faces.application.Application
Object relatedController = context.getApplication().getELResolver().getValue(context.getELContext(), null, relatedControllerString);
C:\Documents and Settings\homi1\My Documents\NetBeansProjects\DBVersionUpdate\src\java\dbversionupdate\SubversionsConverter.java:23: cannot find symbol
symbol : method getELContext()
location: class javax.faces.context.FacesContext
SubversionsController controller = (SubversionsController) facesContext.getApplication().getELResolver().getValue(facesContext.getELContext(), null, "subversions");
C:\Documents and Settings\homi1\My Documents\NetBeansProjects\DBVersionUpdate\src\java\dbversionupdate\SubversionsConverter.java:23: cannot find symbol
symbol : method getELResolver()
location: class javax.faces.application.Application
SubversionsController controller = (SubversionsController) facesContext.getApplication().getELResolver().getValue(facesContext.getELContext(), null, "subversions");
C:\Documents and Settings\homi1\My Documents\NetBeansProjects\DBVersionUpdate\src\java\dbversionupdate\VersionsController.java:275: incompatible types
found : java.lang.Object
required: java.lang.String
return FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(key);
C:\Documents and Settings\homi1\My Documents\NetBeansProjects\DBVersionUpdate\src\java\dbversionupdate\VersionsController.java:388: cannot find symbol
symbol : method getELContext()
location: class javax.faces.context.FacesContext
Object relatedController = context.getApplication().getELResolver().getValue(context.getELContext(), null, relatedControllerString);
C:\Documents and Settings\homi1\My Documents\NetBeansProjects\DBVersionUpdate\src\java\dbversionupdate\VersionsController.java:388: cannot find symbol
symbol : method getELResolver()
location: class javax.faces.application.Application
Object relatedController = context.getApplication().getELResolver().getValue(context.getELContext(), null, relatedControllerString);
C:\Documents and Settings\homi1\My Documents\NetBeansProjects\DBVersionUpdate\src\java\dbversionupdate\VersionsConverter.java:23: cannot find symbol
symbol : method getELContext()
location: class javax.faces.context.FacesContext
VersionsController controller = (VersionsController) facesContext.getApplication().getELResolver().getValue(facesContext.getELContext(), null, "versions");
C:\Documents and Settings\homi1\My Documents\NetBeansProjects\DBVersionUpdate\src\java\dbversionupdate\VersionsConverter.java:23: cannot find symbol
symbol : method getELResolver()
location: class javax.faces.application.Application
VersionsController controller = (VersionsController) facesContext.getApplication().getELResolver().getValue(facesContext.getELContext(), null, "versions");
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
20 errors
C:\Documents and Settings\homi1\My Documents\NetBeansProjects\DBVersionUpdate\nbproject\build-impl.xml:392: The following error occurred while executing this line:
C:\Documents and Settings\homi1\My Documents\NetBeansProjects\DBVersionUpdate\nbproject\build-impl.xml:213: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 0 seconds)
Here is the code that was generated for the MaturityCodesController:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dbversionupdate;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;
import javax.persistence.Query;
import javax.faces.application.FacesMessage;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import javax.faces.FacesException;
import java.util.HashMap;
import javax.faces.validator.ValidatorException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import javax.transaction.UserTransaction;
/**
*
* @author HoMi1
*/
public class MaturityCodesController {
private MaturityCodes maturityCodes = null;
private List<MaturityCodes> maturityCodess = null;
@Resource
private UserTransaction utx = null;
@PersistenceUnit(unitName = "DBVersionUpdatePU")
private EntityManagerFactory emf = null;
public EntityManager getEntityManager() {
return emf.createEntityManager();
}
public int batchSize = 5;
private int firstItem = 0;
private int itemCount = -1;
public void setSubversionsCollectionOfMaturityCodes(Subversions[] subversionsCollection) {
List<Subversions> subversionsCollectionList = Arrays.asList(subversionsCollection);
maturityCodes.setSubversionsCollection(subversionsCollectionList);
}
public Subversions[] getSubversionsCollectionOfMaturityCodes() {
Collection<Subversions> subversionsCollection = maturityCodes.getSubversionsCollection();
if (subversionsCollection == null) {
return new Subversions[0];
}
return subversionsCollection.toArray(new Subversions[0]);
}
public SelectItem[] getMaturityCodessAvailableSelectMany() {
return getMaturityCodessAvailable(false);
}
public SelectItem[] getMaturityCodessAvailableSelectOne() {
return getMaturityCodessAvailable(true);
}
private SelectItem[] getMaturityCodessAvailable(boolean one) {
List<MaturityCodes> allMaturityCodess = getMaturityCodess(true);
int size = one ? allMaturityCodess.size() + 1 : allMaturityCodess.size();
SelectItem[] items = new SelectItem[size];
int i = 0;
if (one) {
items[0] = new SelectItem("", "---");
i++;
}
for (MaturityCodes x : allMaturityCodess) {
items[i++] = new SelectItem(x, x.toString());
}
return items;
}
public MaturityCodes getMaturityCodes() {
if (maturityCodes == null) {
maturityCodes = getMaturityCodesFromRequest();
}
if (maturityCodes == null) {
maturityCodes = new MaturityCodes();
}
return maturityCodes;
}
public String listSetup() {
reset(true);
return "maturityCodes_list";
}
public String createSetup() {
reset(false);
maturityCodes = new MaturityCodes();
return "maturityCodes_create";
}
public String create() {
if (maturityCodes.getSubversionsCollection() == null) {
maturityCodes.setSubversionsCollection(new ArrayList<Subversions>());
}
EntityManager em = getEntityManager();
try {
utx.begin();
List<Subversions> attachedSubversionsCollection = new ArrayList<Subversions>();
for (Subversions subversionsCollectionSubversionsToAttach : maturityCodes.getSubversionsCollection()) {
subversionsCollectionSubversionsToAttach = em.getReference(subversionsCollectionSubversionsToAttach.getClass(), subversionsCollectionSubversionsToAttach.getVersionId());
attachedSubversionsCollection.add(subversionsCollectionSubversionsToAttach);
}
maturityCodes.setSubversionsCollection(attachedSubversionsCollection);
em.persist(maturityCodes);
for (Subversions subversionsCollectionSubversions : maturityCodes.getSubversionsCollection()) {
MaturityCodes oldMaturityCodeOfSubversionsCollectionSubversions = subversionsCollectionSubversions.getMaturityCode();
subversionsCollectionSubversions.setMaturityCode(maturityCodes);
subversionsCollectionSubversions = em.merge(subversionsCollectionSubversions);
if (oldMaturityCodeOfSubversionsCollectionSubversions != null) {
oldMaturityCodeOfSubversionsCollectionSubversions.getSubversionsCollection().remove(subversionsCollectionSubversions);
oldMaturityCodeOfSubversionsCollectionSubversions = em.merge(oldMaturityCodeOfSubversionsCollectionSubversions);
}
}
utx.commit();
addSuccessMessage("MaturityCodes was successfully created.");
} catch (Exception ex) {
try {
if (findMaturityCodes(maturityCodes.getMaturityCode()) != null) {
addErrorMessage("MaturityCodes " + maturityCodes + " already exists.");
} else {
ensureAddErrorMessage(ex, "A persistence error occurred.");
}
utx.rollback();
} catch (Exception e) {
ensureAddErrorMessage(e, "An error occurred attempting to roll back the transaction.");
}
return null;
} finally {
em.close();
}
return listSetup();
}
public String detailSetup() {
return scalarSetup("maturityCodes_detail");
}
public String editSetup() {
return scalarSetup("maturityCodes_edit");
}
private String scalarSetup(String destination) {
reset(false);
maturityCodes = getMaturityCodesFromRequest();
if (maturityCodes == null) {
String requestMaturityCodesString = getRequestParameter("jsfcrud.currentMaturityCodes");
addErrorMessage("The maturityCodes with id " + requestMaturityCodesString + " no longer exists.");
String relatedControllerOutcome = relatedControllerOutcome();
if (relatedControllerOutcome != null) {
return relatedControllerOutcome;
}
return listSetup();
}
return destination;
}
public String edit() {
MaturityCodesConverter converter = new MaturityCodesConverter();
String maturityCodesString = converter.getAsString(FacesContext.getCurrentInstance(), null, maturityCodes);
String currentMaturityCodesString = getRequestParameter("jsfcrud.currentMaturityCodes");
if (maturityCodesString == null || maturityCodesString.length() == 0 || !maturityCodesString.equals(currentMaturityCodesString)) {
String outcome = editSetup();
if ("maturityCodes_edit".equals(outcome)) {
addErrorMessage("Could not edit maturityCodes. Try again.");
}
return outcome;
}
EntityManager em = getEntityManager();
try {
utx.begin();
MaturityCodes persistentMaturityCodes = em.find(MaturityCodes.class, maturityCodes.getMaturityCode());
Collection<Subversions> subversionsCollectionOld = persistentMaturityCodes.getSubversionsCollection();
Collection<Subversions> subversionsCollectionNew = maturityCodes.getSubversionsCollection();
List<Subversions> attachedSubversionsCollectionNew = new ArrayList<Subversions>();
for (Subversions subversionsCollectionNewSubversionsToAttach : subversionsCollectionNew) {
subversionsCollectionNewSubversionsToAttach = em.getReference(subversionsCollectionNewSubversionsToAttach.getClass(), subversionsCollectionNewSubversionsToAttach.getVersionId());
attachedSubversionsCollectionNew.add(subversionsCollectionNewSubversionsToAttach);
}
subversionsCollectionNew = attachedSubversionsCollectionNew;
maturityCodes.setSubversionsCollection(subversionsCollectionNew);
maturityCodes = em.merge(maturityCodes);
for (Subversions subversionsCollectionOldSubversions : subversionsCollectionOld) {
if (!subversionsCollectionNew.contains(subversionsCollectionOldSubversions)) {
subversionsCollectionOldSubversions.setMaturityCode(null);
subversionsCollectionOldSubversions = em.merge(subversionsCollectionOldSubversions);
}
}
for (Subversions subversionsCollectionNewSubversions : subversionsCollectionNew) {
if (!subversionsCollectionOld.contains(subversionsCollectionNewSubversions)) {
MaturityCodes oldMaturityCodeOfSubversionsCollectionNewSubversions = subversionsCollectionNewSubversions.getMaturityCode();
subversionsCollectionNewSubversions.setMaturityCode(maturityCodes);
subversionsCollectionNewSubversions = em.merge(subversionsCollectionNewSubversions);
if (oldMaturityCodeOfSubversionsCollectionNewSubversions != null && !oldMaturityCodeOfSubversionsCollectionNewSubversions.equals(maturityCodes)) {
oldMaturityCodeOfSubversionsCollectionNewSubversions.getSubversionsCollection().remove(subversionsCollectionNewSubversions);
oldMaturityCodeOfSubversionsCollectionNewSubversions = em.merge(oldMaturityCodeOfSubversionsCollectionNewSubversions);
}
}
}
utx.commit();
addSuccessMessage("MaturityCodes was successfully updated.");
} catch (Exception ex) {
try {
String msg = ex.getLocalizedMessage();
if (msg != null && msg.length() > 0) {
addErrorMessage(msg);
} else if (getMaturityCodesFromRequest() == null) {
addErrorMessage("The maturityCodes with id " + currentMaturityCodesString + " no longer exists.");
utx.rollback();
return listSetup();
} else {
addErrorMessage("A persistence error occurred.");
}
utx.rollback();
} catch (Exception e) {
ensureAddErrorMessage(e, "An error occurred attempting to roll back the transaction.");
}
return null;
} finally {
em.close();
}
return detailSetup();
}
public String destroy() {
maturityCodes = getMaturityCodesFromRequest();
if (maturityCodes == null) {
String currentMaturityCodesString = getRequestParameter("jsfcrud.currentMaturityCodes");
addErrorMessage("The maturityCodes with id " + currentMaturityCodesString + " no longer exists.");
String relatedControllerOutcome = relatedControllerOutcome();
if (relatedControllerOutcome != null) {
return relatedControllerOutcome;
}
return listSetup();
}
EntityManager em = getEntityManager();
try {
utx.begin();
maturityCodes = em.getReference(maturityCodes.getClass(), maturityCodes.getMaturityCode());
Collection<Subversions> subversionsCollection = maturityCodes.getSubversionsCollection();
for (Subversions subversionsCollectionSubversions : subversionsCollection) {
subversionsCollectionSubversions.setMaturityCode(null);
subversionsCollectionSubversions = em.merge(subversionsCollectionSubversions);
}
em.remove(maturityCodes);
utx.commit();
addSuccessMessage("MaturityCodes was successfully deleted.");
} catch (Exception ex) {
try {
ensureAddErrorMessage(ex, "A persistence error occurred.");
utx.rollback();
} catch (Exception e) {
ensureAddErrorMessage(e, "An error occurred attempting to roll back the transaction.");
}
return null;
} finally {
em.close();
}
String relatedControllerOutcome = relatedControllerOutcome();
if (relatedControllerOutcome != null) {
return relatedControllerOutcome;
}
return listSetup();
}
private MaturityCodes getMaturityCodesFromRequest() {
String theId = getRequestParameter("jsfcrud.currentMaturityCodes");
return (MaturityCodes) new MaturityCodesConverter().getAsObject(FacesContext.getCurrentInstance(), null, theId);
}
private String getRequestParameter(String key) {
return FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(key);
//return FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(key).toString();
}
public List<MaturityCodes> getMaturityCodess() {
if (maturityCodess == null) {
maturityCodess = getMaturityCodess(false);
}
return maturityCodess;
}
public List<MaturityCodes> getMaturityCodess(boolean all) {
EntityManager em = getEntityManager();
try {
Query q = em.createQuery("select object(o) from MaturityCodes as o");
if (!all) {
q.setMaxResults(batchSize);
q.setFirstResult(getFirstItem());
}
return q.getResultList();
} finally {
em.close();
}
}
private void ensureAddErrorMessage(Exception ex, String defaultMsg) {
String msg = ex.getLocalizedMessage();
if (msg != null && msg.length() > 0) {
addErrorMessage(msg);
} else {
addErrorMessage(defaultMsg);
}
}
public static void addErrorMessage(String msg) {
FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg);
FacesContext.getCurrentInstance().addMessage(null, facesMsg);
}
public static void addSuccessMessage(String msg) {
FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg);
FacesContext.getCurrentInstance().addMessage("successInfo", facesMsg);
}
public MaturityCodes findMaturityCodes(String id) {
EntityManager em = getEntityManager();
try {
MaturityCodes o = (MaturityCodes) em.find(MaturityCodes.class, id);
return o;
} finally {
em.close();
}
}
public int getItemCount() {
if (itemCount == -1) {
EntityManager em = getEntityManager();
try {
itemCount = ((Long) em.createQuery("select count(o) from MaturityCodes as o").getSingleResult()).intValue();
} finally {
em.close();
}
}
return itemCount;
}
public int getFirstItem() {
getItemCount();
if (firstItem >= itemCount) {
if (itemCount == 0) {
firstItem = 0;
} else {
int zeroBasedItemCount = itemCount - 1;
double pageDouble = zeroBasedItemCount / batchSize;
int page = (int) Math.floor(pageDouble);
firstItem = page * batchSize;
}
}
return firstItem;
}
public int getLastItem() {
getFirstItem();
return firstItem + batchSize > itemCount ? itemCount : firstItem + batchSize;
}
public int getBatchSize() {
return batchSize;
}
public String next() {
reset(false);
getFirstItem();
if (firstItem + batchSize < itemCount) {
firstItem += batchSize;
}
return "maturityCodes_list";
}
public String prev() {
reset(false);
getFirstItem();
firstItem -= batchSize;
if (firstItem < 0) {
firstItem = 0;
}
return "maturityCodes_list";
}
private String relatedControllerOutcome() {
String relatedControllerString = getRequestParameter("jsfcrud.relatedController");
String relatedControllerTypeString = getRequestParameter("jsfcrud.relatedControllerType");
if (relatedControllerString != null && relatedControllerTypeString != null) {
FacesContext context = FacesContext.getCurrentInstance();
Object relatedController = context.getApplication().getELResolver().getValue(context.getELContext(), null, relatedControllerString);
try {
Class<?> relatedControllerType = Class.forName(relatedControllerTypeString);
Method detailSetupMethod = relatedControllerType.getMethod("detailSetup");
return (String) detailSetupMethod.invoke(relatedController);
} catch (ClassNotFoundException e) {
throw new FacesException(e);
} catch (NoSuchMethodException e) {
throw new FacesException(e);
} catch (IllegalAccessException e) {
throw new FacesException(e);
} catch (InvocationTargetException e) {
throw new FacesException(e);
}
}
return null;
}
private void reset(boolean resetFirstItem) {
maturityCodes = null;
maturityCodess = null;
itemCount = -1;
if (resetFirstItem) {
firstItem = 0;
}
}
private Map<Object, String> asString = null;
public Map<Object, String> getAsString() {
if (asString == null) {
asString = new HashMap<Object, String>() {
@Override
public String get(Object key) {
if (key instanceof Object[]) {
Object[] keyAsArray = (Object[]) key;
if (keyAsArray.length == 0) {
return "(No Items)";
}
StringBuffer sb = new StringBuffer();
for (int i = 0; i < keyAsArray.length; i++) {
if (i > 0) {
sb.append("<br />");
}
sb.append(keyAsArray[i]);
}
return sb.toString();
}
return new MaturityCodesConverter().getAsString(FacesContext.getCurrentInstance(), null, (MaturityCodes) key);
}
};
}
return asString;
}
public void validateCreate(FacesContext facesContext, UIComponent component, Object value) {
MaturityCodesConverter converter = new MaturityCodesConverter();
String newMaturityCodesString = converter.getAsString(FacesContext.getCurrentInstance(), null, new MaturityCodes());
String maturityCodesString = converter.getAsString(FacesContext.getCurrentInstance(), null, maturityCodes);
if (!newMaturityCodesString.equals(maturityCodesString)) {
createSetup();
}
}
}