4 Replies Latest reply on Jun 29, 2009 8:40 PM by daxxy

    Property in entity not part of db table

    daxxy
      The Devices entity contains a devIp property.  It corresponds to the dev_ip column of the devices table.  devIp is usually an IP address, but sometimes it gets set to 'StackMember'.

      I want to add a boolean property called stackMember.  When devIp equals 'StackMember' I want isStackMember to return true.  Otherwise I want it to return false.

      Ultimately I want to be able to render an outputText depending on the value of stackMember.


      `<h:outputText rendered="#{devices.stackMember}" value="#{devices.devIp}" />`



      Is it possible to declare a property in your entity that does not relate to a column in the table?  Is there some annotation for this?  I tried @Transient, but it didn't work.

      TDR
        • 1. Re: Property in entity not part of db table

          try with this .. put this method in ur entity


          public boolean getRender(){
            int render = false;
            if(stackMember.equals(devIp)){
             render = true;
            }
           return render;
          }
          <h:outputText rendered="#{devices.render}" value="#{devices.devIp}" />
          






          • 2. Re: Property in entity not part of db table
            daxxy

            I should have mentioned in my original posting what I've already tried. 


            I did try this (though I call my boolean stackMember) and get an error.  Here is the code and the error follows:



            public boolean isStackMember() {
                 stackMember = false;
                 if (devIp.startsWith("Stack"))
                      stackMember = true;
                 else
                      stackMember = false;
                 return stackMember;
            }






            Caused by: com.mysql.jdbc.exceptions.
            jdbc4.MySQLSyntaxErrorException: Unknown 
            column 'devices0_.stackMember' in 'field list'






            It's not in the field list because it's not in the database.  But it's in the entity.  How do I tell the app that even though it's in the entity, it should be part of the query because it is NOT in the database?

            • 3. Re: Property in entity not part of db table
              wachtda.scsi.gmx.ch

              This should work with @Transient!

              Maybe it would be better to give your method another name which normaly not is used as getter/setter. (z.B. gotStackMember())?

              • 4. Re: Property in entity not part of db table
                daxxy

                Here is what finally worked.  The thing that made the difference was renaming the getter. Here is the code:


                in Devices.java:


                @Transient
                private boolean stackMember;



                ...


                public boolean gotStackMember() {
                     stackMember = false;
                     if (devIp.startsWith("Stack"))
                          stackMember = true;
                     else
                          stackMember = false;
                     return stackMember;
                }
                     
                public void setStackMember(boolean stackMember) {
                     this.stackMember = stackMember;
                }



                in view:


                <h:outputLink rendered="#{not _device.gotStackMember()}" value="#{interpolator.interpolate(messages['ond.label.url.telnetdevip'], _device.devIp)}">
                     <h:outputText value="#{_device.devIp}" />
                </h:outputLink>
                <h:outputText value="#{_device.devIp}" rendered="#{_device.gotStackMember()}" />



                Thanks for the feedback!


                TDR