3 Replies Latest reply on Dec 20, 2001 11:48 AM by Mark Desrosier

    Read only fields

    John Magee Newbie

      Hi All,
      I have jboss talking to an SQL Server 2000 db. An entity bean maps directly to one of the tables in the database. The problem is, the primary key field in the database is an auto-increment field and, therefore, can't be updated. You can probably see the rest of this question coming. When I do a lookup, followed by a findby, the remote object is returned correctly. But, before i have time to read any of the fields, the persistence kicks in and tries to update the database, which, of course fails because the primary key field isn't availabe for update.

      Any ideas on how I can over ride the persistence of this field, although i still want to read it from the database????

      C:\>java Test
      Got reference
      Have handle to Home interface
      Have handle to Remote interface
      java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
      java.rmi.ServerException: Store failed; nested exception is:
      java.sql.SQLException: [Microsoft][SQLServer JDBC Driver][SQLServer]Cannot update identity column 'CampaignCode'.
      java.rmi.ServerException: Store failed; nested exception is:
      java.sql.SQLException: [Microsoft][SQLServer JDBC Driver][SQLServer]Cannot update identity column 'CampaignCode'.
      java.sql.SQLException: [Microsoft][SQLServer JDBC Driver][SQLServer]Cannot update identity column 'CampaignCode'.
      at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:245)
      at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:220)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:122)
      at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker_Stub.invoke(Unknown Source)
      at org.jboss.ejb.plugins.jrmp.interfaces.GenericProxy.invokeContainer(GenericProxy.java:357)
      at org.jboss.ejb.plugins.jrmp.interfaces.EntityProxy.invoke(EntityProxy.java:133)
      at $Proxy1.getName(Unknown Source)
      at Test.main(Test.java:57) at Test.main(Test.java:57)

        • 1. Declare it to primary key field
          Konstantin Newbie

          If you declare field in question to primary key one,
          [honefully] nobody will ever try to update it...

          • 2. Re: Declare it to primary key field
            John Magee Newbie

            Way ahead of you, the primary key field is set. It must come down to the transaction type. Is it possible to specify that i want the ejb to read the data, but no update it? I know Weblogic has the isDirty flag that can be used to prevent unnecessary re-writes to the database. Does Jboss have something simular??#


            Campaign tracking details
            <ejb-name>Campaign</ejb-name>
            CampaignHome
            Campaign
            <ejb-class>CampaignBean</ejb-class>
            <persistence-type>Container</persistence-type>
            <prim-key-class>java.lang.String</prim-key-class>
            False
            <cmp-field><field-name>CampaignCode</field-name></cmp-field>
            <cmp-field><field-name>Name</field-name></cmp-field>
            <cmp-field><field-name>StartDate</field-name></cmp-field>
            <cmp-field><field-name>Owner</field-name></cmp-field>
            <cmp-field><field-name>Type</field-name></cmp-field>
            <cmp-field><field-name>SelectedRank</field-name></cmp-field>
            <cmp-field><field-name>SelectedTurnover</field-name></cmp-field>
            <cmp-field><field-name>Status</field-name></cmp-field>
            <cmp-field><field-name>MarketSector</field-name></cmp-field>
            <cmp-field><field-name>Description</field-name></cmp-field>
            <cmp-field><field-name>Reason</field-name></cmp-field>
            <cmp-field><field-name>PdfPath</field-name></cmp-field>
            <cmp-field><field-name>EventDate</field-name></cmp-field>
            <cmp-field><field-name>EventSuccess</field-name></cmp-field>
            <cmp-field><field-name>Comments</field-name></cmp-field>
            <cmp-field><field-name>TechnologyFocus</field-name></cmp-field>
            <primkey-field>CampaignCode</primkey-field>

            • 3. Re: Declare it to primary key field
              Mark Desrosier Newbie

              In jaws.xml you can specify the bean as read- only with this:
              <read-only>true</read-only>

              You may also want to set tuned-updates to true, like this:
              <tuned-updates>true</tuned-updates>

              Tuned-updates will suppress the writes after each read.