Reputation: 434
I'm a student trying to make my home work to work. The project is quit simple, only 4 page (xhtml), you can login/logout add new items (books and CD's) and view the items from the DB. Using derby and glassfish, all the software are the latest versions.
The problem:
THe project dosent work on my computer. I sent the hole project to my teacher so that he can look over it and try to find what is wrong, he diden't find anything wrong with the coding, witch means there something wrong with my computer. So I uninstalled everything that have something to do with java, netbeans, derby, maven and glassfish, than deleted the folders for for this software and installed it again, the same problem accures. Tryied with ubuntu and virtualbox, the same thing.
Item.java
package model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
@Entity
@NamedQuery(name = "findAllItems", query = "SELECT i FROM Item i")
public class Item {
// ======================================
// = Attributes =
// ======================================
@Id
@GeneratedValue
protected Long id;
protected String title;
protected Float price;
protected String description;
// ======================================
// = Constructors =
// ======================================
public Item() {
}
public Item(String title, Float price, String description) {
this.title = title;
this.price = price;
this.description = description;
}
// ======================================
// = Getters & Setters =
// ======================================
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Float getPrice() {
return price;
}
public void setPrice(Float price) {
this.price = price;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
ItemController.java
package model;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import java.util.ArrayList;
import java.util.List;
@ManagedBean
@RequestScoped
public class ItemController {
// ======================================
// = Attributes =
// ======================================
@EJB
private ItemEJB itemEJB;
private Book book = new Book();
private CD cd = new CD();
private Item item = new Item();
private List<Item> itemList = new ArrayList<Item>();
// ======================================
// = Public Methods =
// ======================================
public String doNewBook() {
return "newBook.xhtml";
}
public String doNewCD() {
return "newCD.xhtml";
}
public String doCreateBook() {
// book.setDescription(item.getDescription());
// book.setPrice(item.getPrice());
// book.setTitle(item.getTitle());
book = itemEJB.createBook(book);
itemList = itemEJB.findItems();
return "listItems.xhtml";
}
public String doCreateCD() {
// cd.setDescription(item.getDescription());
// cd.setPrice(item.getPrice());
// cd.setTitle(item.getTitle());
cd = itemEJB.createCD(cd);
itemList = itemEJB.findItems();
return "listItems.xhtml";
}
// ======================================
// = Getters & Setters =
// ======================================
public Book getBook() {
return book;
}
public void setBook(Book book) {
this.book = book;
}
public CD getCd() {
return cd;
}
public void setCd(CD cd) {
this.cd = cd;
}
public List<Item> getItemList() {
itemList = itemEJB.findItems();
return itemList;
}
public void setItemList(List<Item> itemList) {
this.itemList = itemList;
}
public Item getItem() {
return item;
}
public void setItem(Item item) {
this.item = item;
}
}
ItemEJB.java
package model;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.util.List;
@Stateless
public class ItemEJB {
// ======================================
// = Attributes =
// ======================================
@PersistenceContext(unitName = "Lab5PU")
private EntityManager em;
// ======================================
// = Public Methods =
// ======================================
public List<Item> findItems() {
Query query = em.createNamedQuery("findAllItems");
return query.getResultList();
}
public Book createBook(Book book) {
em.persist(book);
return book;
}
public CD createCD(CD cd) {
em.persist(cd);
return cd;
}
}
Stack trace:
Looking at the stack trace only tells me that "NamedQuery of name: findAllItems not found." but in my file it look like this "@NamedQuery(name = "findAllItems", query = "SELECT i FROM Item i")". If you need more info about something than just tell me and will post it.
Here is the hole stack trace:
javax.ejb.EJBException
javax.ejb.EJBException
at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5193)
at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5091)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4879)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2039)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1990)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:222)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
at $Proxy145.findItems(Unknown Source)
at model.__EJB31_Generated__ItemEJB__Intf____Bean__.findItems(Unknown Source)
at model.ItemController.getItemList(ItemController.java:83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:302)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at com.sun.el.parser.AstValue.getValue(AstValue.java:116)
at com.sun.el.parser.AstValue.getValue(AstValue.java:163)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:219)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
at javax.faces.component.UIData.getValue(UIData.java:731)
at javax.faces.component.UIData.getDataModel(UIData.java:1798)
at javax.faces.component.UIData.setRowIndexWithoutRowStatePreserved(UIData.java:484)
at javax.faces.component.UIData.setRowIndex(UIData.java:473)
at com.sun.faces.renderkit.html_basic.TableRenderer.encodeBegin(TableRenderer.java:81)
at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:820)
at javax.faces.component.UIData.encodeBegin(UIData.java:1118)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1754)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:401)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.IllegalArgumentException: NamedQuery of name: findAllItems not found.
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getDatabaseQueryInternal(EJBQueryImpl.java:577)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1043)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.createNamedQuery(EntityManagerWrapper.java:533)
at model.ItemEJB.findItems(ItemEJB.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5366)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:144)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:370)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5338)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5326)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:214)
... 58 more
================================================================================== UPDATE & SOLUTION I did fix the problem but I still don't know what was wrong with it. For those who want to know the solution here it comes. I have three HDD on my PC. I moved all files from one drive to the other two. Then print out the project on paper. Then I removed my primary drive with windows 7 x64 on and formatted the empty drive, installed windows 7 (full update), netBeans, maven, glassFish and derby. Wrote down the project in netBeans by hand (no copy), made a new PU and that's it. Just run the project and everything was working now, don't understand it but hey that's life =)
Upvotes: 1
Views: 1463
Reputation: 1297
It cloud be messed up deploy. You should try to clean your project and server, then rebuild and redeploy your app. If it doesn't help you have an error in your code or configuration.
I use declaration of named queries with String constants. It prevents you from making typo in a query name.
@Entity
@NamedQueries({
@NamedQuery(name=Item.QUERY_ALL, query="select i from Item i")})
public class Item implements Serializable {
public static final String QUERY_ALL = "package.Item.all"
// properties ...
}
make query like this
entityManager.createNamedQuery(Item.QUERY_ALL).getResultList();
I hope, this will at least help you to narrow down the problem.
Upvotes: 1