CMP fields’ value being told NULL by the App Server???

This topic contains 8 replies, has 5 voices, and was last updated by  support-swapna 2 weeks, 1 day ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #217273 Reply

    robinsingh
    Member

    ENVIRONMENT DETAILS:
    I have configured myEclipse with jboss 4.0 RC1 version
    on windows XP professional(SP2) using Java[TM] 2 Platform,
    Eclipse Platform
    Version: 3.0.0
    Build id: 200406251208
    jdk version(build 1.4.2_05-b04)
    myEclipse 3.8.2

    hi
    i am deploying a simple entity bean -has 3 files

    bonusbean.java(entity bean definition)
    bonus.java (remote interface)
    bonushome.java(home interface)

    i am doing everything right .
    myEclipse doesnt show any compiler error whatsoever in the files.(no red crosses etc.)
    but when i deploy the application jboss 4.0 RC1 throws exceptions
    saying a particular container managed persistent field -“socsec” doesnt have the accessor methods in the bonusbean.java

    Though i have those methods in bonusbean.java
    and the corresponding declarations are present in the remote interface bonus.java as well.

    i dont understand why is this happening.

    bonusbean.java

    public abstract class BonusBean implements javax.ejb.EntityBean {
    
      public double bonus;
      public String socsec;
    
      
      public abstract String getSocSec();
      public  abstract void setSocSec(String socsec);
      
      public abstract double getBonus();
      public abstract void setBonus(double bonus);
      

    bonus.java (bonus remote interface)

    public interface Bonus extends EJBObject {
      public String getSocSec() throws RemoteException;
      public void setSocSec(String socsec) throws RemoteException;
      
      public double getBonus() throws RemoteException;
      public void setBonus(double bonus) throws RemoteException;
    }
      

    ejb-jar.xml listing

    <enterprise-beans>
       <entity>
          <ejb-name>BonusBean</ejb-name>
          <home>Beans.BonusHome</home>
          <remote>Beans.Bonus</remote>
          <ejb-class>Beans.BonusBean</ejb-class>
          <persistence-type>Container</persistence-type>
          <prim-key-class>java.lang.String</prim-key-class>
          <reentrant>false</reentrant>
          <cmp-version>2.x</cmp-version>
          <abstract-schema-name>bonustable</abstract-schema-name>
          <cmp-field><field-name>bonus</field-name></cmp-field>
          <cmp-field><field-name>socsec</field-name></cmp-field>
          <primkey-field>socsec</primkey-field>
          <security-identity><use-caller-identity/></security-identity>
       </entity>

    jboss error output

    14:09:11,696 INFO  [EARDeployer] Init J2EE application: file:/E:/jboss4/server/default/deploy/BonusApp.ear/
    14:09:12,077 WARN  [verifier] EJB spec violation:
    Bean   : BonusBean
    Section: 10.6.2
    Warning: The entity bean class must define a get accessor for each CMP field.
    Info   : Field: socsec
    
    14:09:12,077 WARN  [verifier] EJB spec violation:
    Bean   : BonusBean
    Section: 10.6.2
    Warning: The entity bean class must define a set accessor for each CMP field.
    Info   : Field: socsec
    
    14:09:12,107 ERROR [MainDeployer] could not create deployment: file:/E:/jboss4/server/default/deploy/BonusApp.ear/BonusAppEJB.
    org.jboss.deployment.DeploymentException: Verification of Enterprise Beans failed, see above for error messages.

    Any help with this will be appreciated.
    thanks .
    regards
    robin

    #217281 Reply

    Scott Anderson
    Participant

    Robin,

    i am doing everything right

    Well, not everything. ūüėČ

    The problem is that you’re violating the javabean spec on the expected names of the accessors. They should be ‘getSocsec’ and ‘setSocsec’. The container doesn’t know that SocSec is a camel-cased shortening of Social Security. So, your versions have the wrong names and thus are not recognized.

    #217290 Reply

    robinsingh
    Member

    thanks that worked.
    Now i am stuck in another weird problem
    kindly help with this .

    In the following listing(bonusservlet.java).

    my field “socsec” is told by the Server to have the null value
    though i have made sure (by all means) that it doenst have null value

    for create(double bonus, String socsec)
    i call create(bonus, “1234”) ; //hardcoding socsec with non-null value
    in the bonusservlet.java code

    still the jboss a.S throws the following exception at the bonusbean.create()method;;

    16:55:52,347 ERROR [BonusBean] Could not create entity
    java.sql.SQLException: General error message from server: "Column 'socsec' cannot be null"
    ---
    ------ at $Proxy64.create(Unknown Source)
     at BonusServlet.doGet(BonusServlet.java:59)
    ----
    -------
    ----
    16:55:52,397 INFO  [STDOUT] javax.ejb.CreateException: Could not create entity:java.sql.SQLException: General error message from server: "Column 'socsec' cannot be null"
    

    when i submit the values from my html page to this servlet
    wich further calls an entity bean bonusbean.create() method
    to create records in to the back-end database called bonusstable.

    (i have already created an empty bonustable in the database by
    create table bonustable(bonus double,socsec char(20))

    If you dont see an immediate error in this . kindly tell me how do i go about debugging this using myEclipse debugging tool .
    though i have tried doing some out.println() statements just before the
    bonusbean.create() method and it shows me non-null values for socsec
    variable. (that’s why i am confused ..as to If i am not sending a null value
    how come server tells me that a null value cannt be put in the socsec column in the backend. )

    bonusServlet.java listing

      public void doGet (HttpServletRequest request, HttpServletResponse response
      ) throws ServletException, IOException {
      String socsec = “1890”, retsocsec = “1891”;
      PrintWriter out;
      response.setContentType(“text/html”);
      String title = “EJB Example”;
      out = response.getWriter();
      out.println(“<HTML><HEAD><TITLE>”);
      out.println(title);
      out.println(“</TITLE></HEAD><BODY>”);

      try {
      //Retrieve Bonus and Social Security Information
      String strMult = request.getParameter(“MULTIPLIER”);
      Integer integerMult = new Integer(strMult);
      multiplier = integerMult.intValue();
      socsec = request.getParameter(“SOCSEC”);
      out.println(“socialsecurity”+socsec);//BROWSER PRINTS THIS non-null value for socsec
      //Calculate bonus
      double bonus = 100.00;

      theCalculation = homecalc.create();
      calc = theCalculation.calcBonus(multiplier, bonus);
      try {
      //Create row in table
      out.println(“socialsecurity ::calc==>”+socsec+”::”+calc);//BROWSER PRINTS THIS non-null value for socsec
      theBonus = homebonus.create(calc,”1234″);
      out.println(“socialsecurity 2::calc==>”+socsec+”::”+calc);
      //browser doesnt print this line coz Exception gets thrown a line before

      //Display data
      out.println(“<H1>Bonus Calculation</H1>”);
      out.println(“<P>Soc Sec passed in: ” + theBonus.getSocsec() + “<P>”);
      out.println(“<P>Multiplier passed in: ” + multiplier + “<P>”);
      out.println(“<P>Bonus Amount calculated: ” +
      theBonus.getBonus() + “<P>”);
      out.println(“</BODY></HTML>”);
      //Catch duplicate key error
      } catch (javax.ejb.DuplicateKeyException e) {
      ——————–
      }
      } catch (Exception CreateException) {
      CreateException.printStackTrace();
      }

    I tried looking around for debug tools but they only debug the standard JAva applications/applets etc. not the servlets .

    this is iimportant for me to know so that i know
    how to go about debugging such Servlet applications in future.
    rather than sending u the code listing.
    (but this time pretty please .. help me ;-))

    #217292 Reply

    robinsingh
    Member

    i saw another table bonusbean automatically made by the Entity EJB on the backend
    i deleted my table bonustable and bean’s automatically generated bonusbean table.

    then i created another table bonusbean

    
    create table bonusbean (bonus double not null default 0, socsec varchar(250) primary key default "333");

    to cover for any other dumb possibilities.
    now the bean while being deployed says…

    Table bonusbean already exists. j2ee application gets started.

    but the servlet still throws the same CreateException at the same point .
    this is really confusing.
    kindly help.

    #593036 Reply

    brizola777
    Participant

    Hi, I know the post is a little old, and I’m doing maintenance on an old system with the same problem. I’m going to put my ejb-jar.xml and Bean if anyone can help me …
    I also use struts2 and XDoclet. Thank you!

    14:19:02,461 WARN [verifier] EJB spec violation:
    Bean : OrganizationUnit
    Section: 10.6.2
    Warning: The entity bean class must define a set accessor for each CMP field.
    Info : Field: idOu

    • This reply was modified 2 weeks, 1 day ago by  brizola777.
    #593045 Reply

    brizola777
    Participant

    Sorry forgot the error:

    14:19:02,461 WARN [verifier] EJB spec violation:
    Bean : OrganizationUnit
    Section: 10.6.2
    Warning: The entity bean class must define a set accessor for each CMP field.
    Info : Field: idOu

    #593054 Reply

    Brian Fernandes
    Moderator

    Hi, I know the post is a little old,

    At only 14 years old, probably a record ūüėČ

    So we’re on the same page, can you let us know:
    1) What version of MyEclipse you are using
    2) Where exactly do you see this error – I’m assuming it’s during deployment, and not in the IDE?
    3) What server/version are you deploying to?

    #593055 Reply

    brizola777
    Participant

    kkkkkkkkkkkk
    sorry my english its mean, im brazilian and this post is only i find on google talking about that.

    Well, I was able to fix the problem (I hope) by changing the name of the variable everywhere idOu to id, not a good practice I know change only to id however was the way I found …

    now the mistake is another ….

    Bean : OrganizationUnit
    Method : public abstract OrganizationUnitLocal postCreate(String, String, String, Long) throws CreateException
    Section: 12.2.11
    Warning: Each local home method must match a method defined in the entity bean class.

    Follows my Local Home class, Local and Bean … I could not understand the error

    You asked me:

    What version of MyEclipse you are using : Neon

    Where exactly do you see this error – I’m assuming it’s during deployment, and not in the IDE – On Console when up Jboss 5.1,
    I do not know if you will understand what I mean by upjboss, I mean when I upload the project in jboss, I’m going to insert an image.

    What server/version are you deploying to – Jboss 5.1

    thank you so much!!!!!!!!!!!!

    • This reply was modified 2 weeks, 1 day ago by  brizola777.
    Attachments:
    You must be logged in to view attached files.
    #593088 Reply

    support-swapna
    Moderator

    brizola777,

    Thank you for the details. I am afraid we cannot provide support for Eclipse as this forum is specifically for MyEclipse IDE and other Genuitec related product issues. Also the problem you are seeing is an EJB development related question and it is better to post in development forums like stackoverflow.com for suggestions from the developer community.

    Sorry that we couldn’t assist further.

    –Swapna
    Genuitec Support

Viewing 9 posts - 1 through 9 (of 9 total)
Reply To: CMP fields’ value being told NULL by the App Server???

This topic is marked as closed to new replies, however your posting capabilities still allow you to do so.