2013-04-15 31 views
0

我有一個表中的列:它具有以下值狀態:P,A,E,C ....JPA實體mappagin不同的值

,因爲我展示一個JSP頁面上此值會我喜歡這個值映射到:P->處理,A - > .... E-> errror,C->完成

,所以我此做了類用於映射值:

import java.util.HashMap; 

public class FactoryStatusValue { 

private static final HashMap<String, String> statusValues; 

static{ 
    statusValues = new HashMap<String, String>(){{ 
     put("C","Completed"); 
     put("E","Errore"); 
     put("T","Terminato"); 
     put("P","Processing"); 
     put("N","Da processare"); 
     put("A","Attivà manuale"); 
    }}; 
} 

public static String getValue(String key){ 
    return statusValues.get(key); 
} 
} 

,並在我這樣做的實體中:

/** 
    * The persistent class for the SETT_TB_BATCHREQUEST database table. 
    * 
    */ 
@Entity 
@Table(name="SETT_TB_BATCHREQUEST") 
public class SettTbBatchrequest implements Serializable { 
private static final long serialVersionUID = 1L; 

@Id 
@SequenceGenerator(name="SETT_TB_BATCHREQUEST_UIDBATCHREQUEST_GENERATOR", sequenceName="SEQ_SETT_TB_BATCHREQUEST" , allocationSize = 1) 
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SETT_TB_BATCHREQUEST_UIDBATCHREQUEST_GENERATOR") 
@Column(unique=true, nullable=false, precision=19) 
private Long uidbatchrequest; 

@Column(length=64) 
private String note; 

@Column(name="\"PARAMETER\"", length=1024) 
private String parameter; 

@Column(length=64) 
private String pdr; 

@Column(length=64) 
private String plant; 

@Column(precision=19) 
private BigDecimal prognum; 

@Column(length=64) 
private String ratecode; 

@Column(length=64) 
private String relco; 

@Temporal(TemporalType.DATE) 
@Column(nullable=false) 
private Date scheddate; 

@Column(name="SETT_DISCO", nullable=false, length=64) 
private String settDisco; 

@Temporal(TemporalType.TIMESTAMP) 
@Column(name="SETT_TIME") 
private Date settTime; 

@Column(name="SETT_USER", length=64) 
private String settUser; 

@Temporal(TemporalType.DATE) 
private Date starttime; 

@Column(nullable=false, length=1) 
private String status; 

@Temporal(TemporalType.TIMESTAMP) 
private Date stoptime; 

//bi-directional many-to-one association to SettTbBatchprocess 
@ManyToOne 
@JoinColumn(name="PROCESSNUM", nullable=false) 
private SettTbBatchprocess settTbBatchprocess; 

//bi-directional many-to-one association to SettTbStoricoRettifica 
@OneToMany(mappedBy="settTbBatchrequest") 
private List<SettTbStoricoRettifica> settTbStoricoRettificas; 

public SettTbBatchrequest() { 
} 

public long getUidbatchrequest() { 
    return this.uidbatchrequest; 
} 

public void setUidbatchrequest(long uidbatchrequest) { 
    this.uidbatchrequest = uidbatchrequest; 
} 

public String getNote() { 
    return this.note; 
} 

public void setNote(String note) { 
    this.note = note; 
} 

public String getParameter() { 
    return this.parameter; 
} 

public void setParameter(String parameter) { 
    this.parameter = parameter; 
} 

public String getPdr() { 
    return this.pdr; 
} 

public void setPdr(String pdr) { 
    this.pdr = pdr; 
} 

public String getPlant() { 
    return this.plant; 
} 

public void setPlant(String plant) { 
    this.plant = plant; 
} 

public BigDecimal getPrognum() { 
    return this.prognum; 
} 

public void setPrognum(BigDecimal prognum) { 
    this.prognum = prognum; 
} 

public String getRatecode() { 
    return this.ratecode; 
} 

public void setRatecode(String ratecode) { 
    this.ratecode = ratecode; 
} 

public String getRelco() { 
    return this.relco; 
} 

public void setRelco(String relco) { 
    this.relco = relco; 
} 

public Date getScheddate() { 
    return this.scheddate; 
} 

public void setScheddate(Date scheddate) { 
    this.scheddate = scheddate; 
} 

public String getSettDisco() { 
    return this.settDisco; 
} 

public void setSettDisco(String settDisco) { 
    this.settDisco = settDisco; 
} 

public Date getSettTime() { 
    return this.settTime; 
} 

public void setSettTime(Date settTime) { 
    this.settTime = settTime; 
} 

public String getSettUser() { 
    return this.settUser; 
} 

public void setSettUser(String settUser) { 
    this.settUser = settUser; 
} 

public Date getStarttime() { 
    return this.starttime; 
} 

public void setStarttime(Date starttime) { 
    this.starttime = starttime; 
} 

public String getStatus() { 
    return FactoryStatusValue.getValue(this.status); 
} 

public void setStatus(String status) { 
    this.status = FactoryStatusValue.getValue(status); 
} 

public Date getStoptime() { 
    return this.stoptime; 
} 

public void setStoptime(Date stoptime) { 
    this.stoptime = stoptime; 
} 

public SettTbBatchprocess getSettTbBatchprocess() { 
    return this.settTbBatchprocess; 
} 

public void setSettTbBatchprocess(SettTbBatchprocess settTbBatchprocess) { 
    this.settTbBatchprocess = settTbBatchprocess; 
} 

public List<SettTbStoricoRettifica> getSettTbStoricoRettificas() { 
    return this.settTbStoricoRettificas; 
} 

public void setSettTbStoricoRettificas(List<SettTbStoricoRettifica> settTbStoricoRettificas)   { 
    this.settTbStoricoRettificas = settTbStoricoRettificas; 
} 

    } 

但該表總是顯示: E,P,A,C ...... 爲什麼?

爲completenss這是jsp頁面

<%@ taglib uri="http://www.sun.com/webui/webuijsf" prefix="webuijsf"%> 
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> 
    <%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%> 
    <%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%> 
    <f:view> 
<f:loadBundle basename="it.eni.italgas.sam.web.dictionary" 
    var="bundle" /> 
<webuijsf:page id="page1" rendered="#{UserBean.userEnabled}"> 
    <webuijsf:html id="html1"> 
     <webuijsf:head id="head1" parseOnLoad="false" 
      title="Pagina di prova2" webuiOnLoad="false"> 
      <webuijsf:link id="link1" url="/resources/stylesheet.css" /> 
     </webuijsf:head> 
     <webuijsf:body id="body1" style="-rave-layout: grid" 
     styleClass="pageLayout"> 

     <webuijsf:form id="form1"> 
      <webuijsf:label id="label3" 
      style="font-size: 14px; left: 24px; top: 24px; position: absolute" 
      text="#{bundle.TitoloPaginaRisultatiRettifiche_02}"/> 

      <webuijsf:button id="button3" actionExpression="#{guiRisultati_02.button1_action}" style="height: 24px; left: 48px; top: 120px; position: absolute; width: 96px" text="#{bundle.refresh}"/> 

      <!-- inizio tabella --> 
      <webuijsf:table id="table1" paginateButton="true" 
       paginationControls="true" 
       style="height: 52px; left: 48px; top: 168px; position: absolute; width: 1840px" 
       title="#{bundle.TitoloTabella}"> 
       <webuijsf:tableRowGroup id="tableRowGroup2" rows="10" 
        sourceData="#{GUISessionBeanDisplayRett.provider}" sourceVar="richiesta"> 
        <webuijsf:tableColumn headerText="#{bundle.UidBatchrequest}" 
         id="tableColumn13" sort="uidbatchrequest"> 
         <webuijsf:staticText id="staticText11" 
          text="#{richiesta.value.uidbatchrequest}" /> 
        </webuijsf:tableColumn> 
        <webuijsf:tableColumn headerText="#{bundle.Scheddate}" 
         id="tableColumn7" sort="scheddate"> 
         <webuijsf:staticText id="staticText12" 
          converter="#{guiRisultati_02.sqlDateConverter1}" 
          text="#{richiesta.value.scheddate}" /> 
        </webuijsf:tableColumn> 
        <webuijsf:tableColumn headerText="#{bundle.DataInizio}" 
         id="tableColumn5" sort="starttime"> 
         <webuijsf:staticText id="staticText13" 
          converter="#{guiRisultati_02.sqlDateConverter1}" 
          text="#{richiesta.value.starttime}" /> 
        </webuijsf:tableColumn> 
        <webuijsf:tableColumn headerText="#{bundle.DataFine}" 
         id="tableColumn6" sort="stoptime"> 
         <webuijsf:staticText id="staticText14" 
          converter="#{guiRisultati_02.sqlDateConverter2}" 
          text="#{richiesta.value.stoptime}" /> 
        </webuijsf:tableColumn> 
        <webuijsf:tableColumn headerText="#{bundle.Status}" 
         id="tableColumn8" sort="status"> 
         <webuijsf:staticText id="staticText15" 
          text="#{richiesta.value.status}" /> 
        </webuijsf:tableColumn> 
        <webuijsf:tableColumn headerText="#{bundle.SdV}" 
         id="tableColumn9" sort="relco"> 
         <webuijsf:staticText id="staticText16" 
          text="#{richiesta.value.relco}" /> 
        </webuijsf:tableColumn> 
        <webuijsf:tableColumn headerText="#{bundle.Impianto}" 
         id="tableColumn10" sort="plant"> 
         <webuijsf:staticText id="staticText17" 
          text="#{richiesta.value.plant}" /> 
        </webuijsf:tableColumn> 
        <webuijsf:tableColumn headerText="#{bundle.Pdr}" 
         id="tableColumn11" sort="pdr"> 
         <webuijsf:staticText id="staticText18" 
          text="#{richiesta.value.pdr}" /> 
        </webuijsf:tableColumn> 
        <webuijsf:tableColumn headerText="#{bundle.Parametri}" 
         id="tableColumn12" sort="parameter"> 
         <webuijsf:staticText id="staticText19" 
          text="#{richiesta.value.parameter}" /> 
        </webuijsf:tableColumn> 

        <webuijsf:tableColumn headerText="#{bundle.DataUltimaModifica}" 
         id="tableColumn200" sort="settTime"> 
         <webuijsf:staticText id="staticText200" 
          converter="#{guiRisultati_02.sqlDateConverter2}" 
          text="#{richiesta.value.settTime}" /> 
        </webuijsf:tableColumn> 

        <!-- colonne di modifica --> 
        <webuijsf:tableColumn id="tableColumn2" styleClass="buttonColumn"> 
         <webuijsf:button actionExpression="#{guiRisultati_02.button4_action}" 
          id="button5" text="#{bundle.BottoneDettagli}"> 
          <f:setPropertyActionListener 
           target="#{GUISessionBeanDisplayRett.uidBatchrequest}" 
           value="#{richiesta.value.uidbatchrequest}" /> 
         </webuijsf:button> 
        </webuijsf:tableColumn> 
        <!-- parte colonna con eliminazione --> 


       </webuijsf:tableRowGroup> 
      </webuijsf:table> 





     </webuijsf:form> 


     </webuijsf:body> 
    </webuijsf:html> 
</webuijsf:page> 

+0

你能證明你的jsp? – sanbhat

+0

是的,我編輯的問題 –

+0

我想我沒有理解問題,哪個表仍然顯示E,A,P ...? jsp表或OR數據庫表? – sanbhat

回答

1

我經常觀察到,Hibernate不調用您的實體getter在訪問特定

例如,如果status是一個字段,並且有人試圖呼叫getStatus(),hibernate不會調用您的實體的getStatus()方法。

因此,這將是更好的聲明transient場(不映射成一列)稱爲longStatus(說)你的實體類和有這方面的getter像下面。

private transient longStatus; 

public String getLongStatus() { 
    return FactoryStatusValue.getValue(this.status); 
} 

您可能需要修改你的JSP訪問的entity.longStatus代替entity.status.

+0

好的,讓我試試非常感謝你 –

+0

你是一個天才男人!請你能解釋一下爲什麼需要Transient關鍵字? –

+1

'transient'關鍵字使得hibernate在映射時忽略該字段。如果一個字段被聲明爲'transient',那麼hibernate不會嘗試將它映射到表中的任何一列,實體指向。 由於longStatus只是您的實體類中的一次性非持久性字段,因此使其「暫時」變得有意義 – sanbhat