1

I am using JPA and JSF for a small web application. It's a maven project in Netbeans. And also I am using Primefaces.

I have a entity class with two columns, restaurantName and seats.

I can get data from the restaurantName-column and display it on the app(website) but not from the seats-column. When I try to display seats-data, the website acts wierd in that way that the datatable with the data disappears and also half the website disappears.

Here is the code for the datatable:

<p:dataTable var="restaurants" value="#{restaurantBB.allRestaurants}">
                        <p:column headerText="Restaurants">
                            <p:graphicImage value="/resources/images/mcdonalds.png"/>
                            <h:outputText value="#{restaurants.name}" />
                        </p:column>
                        <p:column headerText="Seats">
                             <h:outputText value="#{restaurants.seats}" />
                        </p:column>
                    </p:dataTable>

The restaurantBB.allRestaurants part returns a list with all the restaurants. I have several other entity-classes where they all work just fine.

Here is the entity-class:

@Entity
@Table(name="RESTAURANTS")
public class Restaurants extends AbstractEntity {

    @Column(nullable = false)
    private String name;
    @Column(nullable = false)
    private String seats;

    public Restaurants() {
        ;
    }

    public Restaurants(String name) {
        this.name = name;
        seats = "23";
    }

    public Restaurants(Long id, String name) {
        super(id);
        this.name = name;
        seats = "23";
    }

    @Override
    public String toString() {
        return "Restaurants{" + "id=" + getId() + ", name=" + getName() + '}';
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the seats
     */
    public String getSeats() {
        return seats;
    }

I have set the seats variable to "23" for testing purposes. If you need other code just tell me please.

EDIT: NetBeans throws this error:

The class 'c.c.c.c.c.Restaurants' does not have the property 'seats

I'm not sure what I do here? Anyone?

EDIT 2:

FATAL:   JSF1073: javax.el.PropertyNotFoundException caught during processing of RENDER_RESPONSE 6 : UIComponent-ClientId=, Message=/index.xhtml @150,74 value="#{restaurants.seats}": The class 'c.c.c.c.c.Restaurants' does not have the property 'seats'.
FATAL:   /index.xhtml @150,74 value="#{restaurants.seats}": The class 'c.c.c.c.c.Restaurants' does not have the property 'seats'.
javax.el.PropertyNotFoundException: /index.xhtml @150,74 value="#{restaurants.seats}": The class 'c.c.c.c.c.Restaurants' does not have the property 'seats'.
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:111)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
    at javax.faces.component.UIOutput.getValue(UIOutput.java:174)
    at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355)
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
    at org.primefaces.component.column.Column.renderChildren(Column.java:304)
    at org.primefaces.component.datatable.DataTableRenderer.encodeCell(DataTableRenderer.java:963)
    at org.primefaces.component.datatable.DataTableRenderer.encodeRow(DataTableRenderer.java:919)
    at org.primefaces.component.datatable.DataTableRenderer.encodeRows(DataTableRenderer.java:830)
    at org.primefaces.component.datatable.DataTableRenderer.encodeTbody(DataTableRenderer.java:777)
    at org.primefaces.component.datatable.DataTableRenderer.encodeTbody(DataTableRenderer.java:740)
    at org.primefaces.component.datatable.DataTableRenderer.encodeRegularTable(DataTableRenderer.java:264)
    at org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.java:226)
    at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:85)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:456)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
    at java.lang.Thread.run(Thread.java:745)
Caused by: javax.el.PropertyNotFoundException: The class 'c.c.c.c.c.Restaurants' does not have the property 'seats'.
    at javax.el.BeanELResolver.getBeanProperty(BeanELResolver.java:731)
    at javax.el.BeanELResolver.getValue(BeanELResolver.java:351)
    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:140)
    at com.sun.el.parser.AstValue.getValue(AstValue.java:204)
    at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:226)
    at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
    ... 56 more
CJR
  • 3,174
  • 6
  • 34
  • 78
  • and where is JDBC in all of this? I see no JDBC code. I see no JPA query either for that matter. – Neil Stockton Oct 18 '16 at 13:55
  • I have the database as a local JDBC, should I edit my tags and question and remove jdbc?? – CJR Oct 18 '16 at 13:57
  • 2
    There is no such thing as a local JDBC, there is such a thing as a local database. JDBC is the low level API in Java to communicate with a database and you are not using it here, so yes the tag is unnecessary. In any case the behavior you describe sounds like an exception is happening, check the server log file. – Gimby Oct 18 '16 at 14:01
  • @Gimby Yes, youre right. It said "The class 'com.Restaurants' does not have the property 'seats'. What does it mean? I'm not sure what to do here. – CJR Oct 18 '16 at 14:13
  • 1
    Where do you see that error? You say "Netbeans throws this error", where does it show it? – Gimby Oct 18 '16 at 14:17
  • @Gimby in the GlassFish output log, should I edit it in my post? – CJR Oct 18 '16 at 14:27
  • Not the entire log but there is probably an exception stacktrace attached to that error, post that. – Gimby Oct 18 '16 at 14:29
  • @Gimby Ok I have done that, its in the bottom of my pots. – CJR Oct 18 '16 at 14:32
  • 1
    since in your xhtml page you do not reference `.seats` but `.name` twice, it cannot be jsf related. Or the code that you show is not the code that you run... Please create a [mcve] – Kukeltje Oct 18 '16 at 14:34
  • @Kukeltje Sorry I had copy&pasted wrong part of the code. It's supposed to say "seats". the double name part was a test to se if it was a column error. But the error is when I try with .seats – CJR Oct 18 '16 at 14:36
  • 2
    Have you tried adding the seats setter, i.e. `setSeats(String seats)`? – Nikos Paraskevopoulos Oct 18 '16 at 14:39
  • @NikosParaskevopoulos I just did, still have the same problem :/ – CJR Oct 18 '16 at 14:42
  • 2
    @Carlton: are you 1000% sure the change adding the setter is also deployed? And my [mcve] suggestion still stands... please create it. – Kukeltje Oct 18 '16 at 15:00
  • 1
    Do you have 2 Restaurants entities? edu.cth.dzenkyair.backend.core.Restaurants and com.Restaurants? – Jaqen H'ghar Oct 19 '16 at 07:30
  • @JaqenH'ghar: I think the OP might just be 'sloppy' in this case... – Kukeltje Oct 19 '16 at 11:04
  • @JaqenH'ghar No I just edited it for the post, its the same entity. – CJR Oct 20 '16 at 16:15
  • @Kukeltje I have added some links, can you look at them please? – CJR Oct 20 '16 at 16:45
  • 1
    You still have not posted a [mcve] here. The code in your question is still wrong. Please improve that. – Kukeltje Oct 20 '16 at 17:49
  • 1
    Check with a log file what your findAllRestaurants returns... could be you use a non-typed query and it actually returns a `List` instead of `List`. If so, this is a duplicate of a StackOverflow post that I cannot find but @BalusC most likely can – Kukeltje Oct 20 '16 at 19:02
  • 1
    Fist thing to look into is your database with that kind of exception. 'Restaurants does not have the property seats' clearly states, that the query fails. Please look into your database-schema to clarify that. – XiCoN JFS Oct 21 '16 at 09:14
  • 1
    @XiCoNJFS: if the query fails, this error would not occur... – Kukeltje Oct 21 '16 at 10:01
  • 1
    See http://stackoverflow.com/questions/13700565/jpa-query-getresultlist-use-in-a-generic-way (the 'jpa 2.0' related answer) – Kukeltje Oct 21 '16 at 10:14
  • @Kukeltje Thanks for all the comments! I do use a typerquery and it does return the expected list, just without the seats variable :( – CJR Oct 26 '16 at 17:25
  • In your code in github, you do *not* use a typedquery... – Kukeltje Oct 26 '16 at 17:39
  • @Kukeltje I do use it in my get method in AbstractDAO? But I don't for the count ? Is that what you mean? – CJR Oct 26 '16 at 19:28

2 Answers2

1

You are getting this error because there is no associated setter for the seats column.

When a row from the database is read, the no argument constructor is called to generate an instance of the entity. Then for each column in the table, an associated set method is used to populate the fields of the entity.

Without an appropriate set method, the entity cannot be populated with the value from the seats column.

Xavier Hammond
  • 277
  • 1
  • 5
  • Thanks for your answer! I added the setter and still have the problem :( – CJR Oct 26 '16 at 17:23
  • 1
    This answer is incorrect. The provider will access the field. Otherwise you'd be forced to expose fields you may not want to. – Alan Hay Oct 26 '16 at 17:41
-1

Looks like the column seats is not in your database-table RESTAURANTS. BTW: naming your entities in plural is actually bad practice, not wrong, but just not common design. Name your entities in singular, so you can differ from a list ("restaurants") and a single entity ("restaurant").

To fix your problem, just add the column manually to your database or let eclipseLink handle schema- and table-creation. Just add the following property to your persistence.xml:

<property name="eclipselink.ddl-generation" value="create-or-extend-tables"/>

Now on deploy eclipseLink will create new tables, join-tables and columns whenever there is a change in your entities. This is the very lazy and handy approach to automate your database-creation.

Oh one sidenote: looks like you copy-pasted a lot of abstract classes from outside projects to your project (AbstractEntity, AbstractDAO), since I've seen that code many times before. No offence, but for a beginner it is best to write that kind of code yourself.

XiCoN JFS
  • 628
  • 3
  • 12
  • 4
    although your remarks are valid (plural et al, could have added that 'seats' being a string instead of an int is 'wrong' to) I'm 100% sure this is not causing this error. OP would have gotten different errors then. – Kukeltje Oct 21 '16 at 10:00
  • I will give this a try! Thanks will let you know it if works. – CJR Oct 26 '16 at 17:23
  • For some wierd reason, it actually worked. I already had this in my persistence file ( ), and already had working entities with several variables, but when I added the your part to it, it now works with my entity with the seats variable. It also fixed another problem I had with not being able to see my tables in the Service tab in Netbeans. Thank you. – CJR Oct 27 '16 at 10:29
  • Btw, I have another problem with my project. Whenever I run my application ( I have a (at)startup (at)singleton file where I create test data for my entities) it adds the newly created data. But here is the thing, It doesnt remove the data, so eveytime i run my app i have several copies of the same data (diferent ID's for them). My application does remove data from the tables, but somehow theyre still there in Netbeans. Any ideas on how to remove it? – CJR Oct 27 '16 at 10:31
  • glad it helped, sometimes exceptions are not as clear as supposed to... looked like an ui bug, but the getters where there, so I assumed it must be an entity-related issue (for anyone who downvoted me). For your issue @Carlton: if your startup-class adds data, without checking if data exists, of course it will add more data. Either build in a check or recreate your db on every startup (for the lazy) ---> just put in the value `drop-and-create-tables` in the ddl-generation. – XiCoN JFS Oct 28 '16 at 10:13