jpa - jsf - foreign key in datatable -


i'm showing list of orders in datatable , , 1 of columns must show customer_id of order: customer_id fk in manytoone relationship.

customer entity

@entity public class customer {      ///other columns      @onetomany(mappedby = "cliente", fetch=fetchtype.eager)     private list<order> orders; 

order entity

    @entity @table(name = "orders")  public class order implements serializable{      /**      *       */     private static final long serialversionuid = 1l;       @id     @generatedvalue(strategy = generationtype.auto)     private long id;       @column (nullable = false)     private string state;      @column (nullable = false)     @temporal(temporaltype.timestamp)     private calendar openingdate;      @column (nullable = true)     @temporal(temporaltype.timestamp)     private calendar closingdate;      @column (nullable = true)     @temporal(temporaltype.timestamp)     private calendar evadingdate;      @manytoone(cascade={ cascadetype.persist, cascadetype.remove },fetch=fetchtype.lazy)     @joincolumn(name = "customer_id")      private customer customer; 

and finally, page i'm putting datatable orders.

showorders.xhtml

<h:datatable id="list" value="#{ordercontroller.orders}"         var="order">         <h:column>             <f:facet name="header">nome</f:facet>             <h:commandlink action="#{ordercontroller.findorder}"                 value="#{order.id}" style="color: orange">                 <f:setpropertyactionlistener target="#{ordercontroller.id}"                     value="#{order.id}" />             </h:commandlink>         </h:column>         <h:column>             <f:facet name="header">stato</f:facet>             <h:outputtext value="#{order.state}" />         </h:column>         <h:column>             <f:facet name="header">data apertura</f:facet>             <h:outputtext value="#{order.openingdate.time}">                 <f:convertdatetime datestyle="full" type="date" />             </h:outputtext>         </h:column>         <h:column>             <f:facet name="header">data chiusura</f:facet>             <h:outputtext value="#{order.closingdate.time}">                 <f:convertdatetime datestyle="full" type="date" />             </h:outputtext>         </h:column>         <h:column>             <f:facet name="header">data evasione</f:facet>             <h:outputtext value="#{order.evadingdate.time}">                 <f:convertdatetime datestyle="full" type="date" />             </h:outputtext>         </h:column>         <h:column>             <f:facet name="header">id cliente</f:facet>             <h:commandlink action="#{registercustomer.detailscustomer}"                 value="#{order.customer.id}" style="color: orange">                 <f:setpropertyactionlistener target="#{registercustomer.id}"                     value="#{order.customer.id}" />              </h:commandlink>         </h:column> 

problem is, fine except customer_id, doesn't show on page. wrong? i've tried looot of things, changed type of fetching, changed relationships...but i'm start thinking it's java problem , if can't find solution or explanation on internet. me? i'm stuck :/

since order related customer here need still use lazy loading able initilize customer of given order

        session = hibernateutil.getsessionfactory().getcurrentsession();          session.begintransaction();         ord = (order) session.get(order.class, id_order);         hibernate.initialize(ord.getcustomer());         session.gettransaction().commit();         customer cust = ord.getcustomer(); 

also check have set , related customer_id join

customer getcustomer() { } setcustomer(customer cust) { } 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -