Package structure suitable for entity beans

hi,
I have to manage some good number of entity beans ( around 250 )
is it a good idea to package these beans.
i mean what number of packages could be an idea one.
currently we have 5 packages and around 50 beans will be in each.
can anybody suggest on this..

package structure should be based more on the business context rather than number of beans. Usually it is of the form..
org/com.<company_name>.<proj_name>.<context>.entity
for instance...a good package structe example is
org.apache.log4j.Category !
If you have customer and order beans then
com.walmart.pos.customer.entity
com.walmart.pos.order.entity
hth...
sanjay.

Similar Messages

  • How to disable cache implementation in 8.1 SP6 for entity beans

    How to disable cache implementation in 8.1 SP6 for entity beans
    In our production environment, we want to disable cache implementation for entity beans. We are using weblogic 8.1 SP6.
    Weblogic cache implementation has been causing many cachefull exceptions so we want that it fetches the data from database everytime instead of cache.

    Check the "max-beans-in-cache" setting in your weblogic-ejb-jar.xml. The cache full exception, means that a new bean could not be created because of this cache being full.
    Nothing to do with fetching from the database directly.
    If you really want direct fetches then do not use beans at all. Consider using direct JDCB/SQL calls (without a entity bean) to fetch huge data.
    Let's again review your application based on the below explanation before making a decision on which configuration change to perform:
    If you truly have many ejbs simultaneously enrolled in transactions, then yes, the cache must be big enough to hold all the instances.
    Your cache must have a max size large enough to handle your peak simultaneous transaction load.
    Also, try to ask the following query to your application developer. Does every user actually have to have more than one bean in the cache ? Are many of these values read-only reference values that are not updated ?
    SOLUTION CHOICE:
    1. If you are testing with more number of users simultaneously, then you will need to increase the "max-beans-in-cache" setting in your weblogic-ejb-jar.xml to match the load.
    2. If you have few users but still seeing a lot of beans, then consult with your application developer and try to ask the above questions (Does every user have more than......) and based on that try to redesign/tune your application to make it an effective Entity bean model.
    3. If you have queries where huge result sets are returned, consider using plain/direct JDB/SQL calls.
    Arun

  • 2 phase commit for entity bean

    Hi all,
    Does the 2-phase commit capability in WL6.X applies to entity bean?
    Thanks,
    Rick

    Two phase commit is the mechanism that allows transactions to the managed
    across different servers and databases.
    yes, definitely I does apply for entity beans
    "Rick Lee" <[email protected]> wrote in message
    news:[email protected]..
    >
    Hi all,
    Does the 2-phase commit capability in WL6.X applies to entity bean?
    Thanks,
    Rick

  • How set diff. timeouts for entity beans?

    How do i set diff. timeouts for diff. entity beans? Is it in the ejb-jar.xml file? Is this refreshed every time it is accesses?

    Hi there,
    Although not familiar with all of the App servers on the market, I'd say that you are unlikely to find a timeout value for Entity Beans. Passivation of Entity beans is normally a function of the commit options supported by a specific App server. For example, with Commit Option C an entity bean instance should always be returned to the instance pool after a transaction has completed. You can find details of the various commit options in the EJB specification which you can view or download from:
    http://java.sun.com/products/ejb/docs.html
    Hope this helps
    Amanda
    Developer Technical Support
    Sun Microsystems
    http://www.sun.com/developers

  • Do I need to Create Primary Key Class for Entity beans with Local interface

    Do I need to Create Primary Key Class for Entity beans with Local interface?
    I have created my entity bean with the wizard in Sun One Studio and it does not create a primary key class for you.
    I thought that the primary key class was required. My key is made up of only one field.
    Anyone know the answer.
    Jim

    u dont need to create a primary key class for a entity bean.if ur table's primary key feild(int ,float) is a built in or primitive data type,then u dont need one.But if ur table has a primary key field which is non primitive (for example StudentID,ItemID etc)then u have to create a primary key class.
    hope this helps :-)

  • Do JNDI look up for entity beans from a session bean  in different  jars

    I have a problem doing entity beans JNDI look up from a session bean which is deployed
    as a separate package (session.jar) from the entity beans (entity.jar)
    I believe if both session bean and entity beans are deployed into one jar and
    I specify ejb-local-reference-description for session bean, it should work. However,
    due to some reason, they have to be in separated packages but still in the same
    container. Then question how to do JNDI lookup given entity beans only have local
    interfaces?
    FYI.
    1 both session.jar and entity.jar are self-contained. i.e., no deployment error.
    each JNDI name can be viewed from JNDI tree
    2. weblogic-ejb-jar.xml for session.jar
    <weblogic-ejb-jar>
    <description><![CDATA[Generated by XDoclet]]></description>
    <weblogic-enterprise-bean>
    <ejb-name>PetstoreLogic</ejb-name>
    <stateless-session-descriptor>
    </stateless-session-descriptor>
    <reference-descriptor>
    </reference-descriptor>
    <jndi-name>PetstoreLogic</jndi-name>
    <local-jndi-name>PetstoreLogicLocal</local-jndi-name>
    </weblogic-enterprise-bean>
    </weblogic-ejb-jar>
    3. weblogic-ejb-jar.xml (code snip) for entity.jar
    <weblogic-enterprise-bean>
    <ejb-name>Account</ejb-name>
    <entity-descriptor>
    <persistence>
    <persistence-type>
    <type-identifier>WebLogic_CMP_RDBMS</type-identifier>
    <type-version>6.0</type-version>
    <type-storage>META-INF/weblogic-cmp-rdbms-jar.xml</type-storage>
    </persistence-type>
    <persistence-use>
    <type-identifier>WebLogic_CMP_RDBMS</type-identifier>
    <type-version>6.0</type-version>
    </persistence-use>
    </persistence>
    </entity-descriptor>
    <reference-descriptor>
    </reference-descriptor>
    <local-jndi-name>net.sourceforge.cpetstore/AccountLocalHome</local-jndi-name>
    </weblogic-enterprise-bean>
    4. if I do
    accountLocalHome = (AccountLocalHome) ic.lookup("net/sourceforge/cpetstore/AccountLocalHome");
    get error like:
    javax.naming.LinkException: . Root exception is javax.naming.NameNotFoundException:
    While trying to look up /app/ejb/net.sourceforge.cpetstore-entity.jar#Account/local-home
    in /app/ejb/cpetstore-ejb.jar#PetstoreLogic.; remaining name '/app/ejb/net/sourceforge/cpetstore-entity/jar#Account/local-home'
         at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:869)
         at weblogic.jndi.internal.ApplicationNamingNode.lookup(ApplicationNamingNode.java:150)
         at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:338)

    In weblogic-ejb-jar.xml use jndi-name instead of local-jndi-name in reference-descriptor
    element.
    "Qiming He" <[email protected]> wrote:
    >
    I have a problem doing entity beans JNDI look up from a session bean
    which is deployed
    as a separate package (session.jar) from the entity beans (entity.jar)
    I believe if both session bean and entity beans are deployed into one
    jar and
    I specify ejb-local-reference-description for session bean, it should
    work. However,
    due to some reason, they have to be in separated packages but still in
    the same
    container. Then question how to do JNDI lookup given entity beans only
    have local
    interfaces?
    FYI.
    1 both session.jar and entity.jar are self-contained. i.e., no deployment
    error.
    each JNDI name can be viewed from JNDI tree
    2. weblogic-ejb-jar.xml for session.jar
    <weblogic-ejb-jar>
    <description><![CDATA[Generated by XDoclet]]></description>
    <weblogic-enterprise-bean>
    <ejb-name>PetstoreLogic</ejb-name>
    <stateless-session-descriptor>
    </stateless-session-descriptor>
    <reference-descriptor>
    </reference-descriptor>
    <jndi-name>PetstoreLogic</jndi-name>
    <local-jndi-name>PetstoreLogicLocal</local-jndi-name>
    </weblogic-enterprise-bean>
    </weblogic-ejb-jar>
    3. weblogic-ejb-jar.xml (code snip) for entity.jar
    <weblogic-enterprise-bean>
    <ejb-name>Account</ejb-name>
    <entity-descriptor>
    <persistence>
    <persistence-type>
    <type-identifier>WebLogic_CMP_RDBMS</type-identifier>
    <type-version>6.0</type-version>
    <type-storage>META-INF/weblogic-cmp-rdbms-jar.xml</type-storage>
    </persistence-type>
    <persistence-use>
    <type-identifier>WebLogic_CMP_RDBMS</type-identifier>
    <type-version>6.0</type-version>
    </persistence-use>
    </persistence>
    </entity-descriptor>
    <reference-descriptor>
    </reference-descriptor>
    <local-jndi-name>net.sourceforge.cpetstore/AccountLocalHome</local-jndi-name>
    </weblogic-enterprise-bean>
    4. if I do
    accountLocalHome = (AccountLocalHome) ic.lookup("net/sourceforge/cpetstore/AccountLocalHome");
    get error like:
    javax.naming.LinkException: . Root exception is javax.naming.NameNotFoundException:
    While trying to look up /app/ejb/net.sourceforge.cpetstore-entity.jar#Account/local-home
    in /app/ejb/cpetstore-ejb.jar#PetstoreLogic.; remaining name '/app/ejb/net/sourceforge/cpetstore-entity/jar#Account/local-home'
         at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:869)
         at weblogic.jndi.internal.ApplicationNamingNode.lookup(ApplicationNamingNode.java:150)
         at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:338)

  • Creating jar file for entity bean

    I am trying to deploy an entity bean..i compiled all the java files and created a dir by name META_INF and copied ejb-jar.xml
    and the other two .xml files which are needed to this dir. then using ,ant i tried to create the jar file ,,but it is giving the following error
    during the process ..PLs Help me
    Buildfile: build.xml
    clean:
    [delete] Deleting directory D:\ejb\entity\build
    [delete] Deleting directory D:\ejb\entity\dist
    init:
    [mkdir] Created dir: D:\ejb\entity\build
    [mkdir] Created dir: D:\ejb\entity\build\META-INF
    [mkdir] Created dir: D:\ejb\entity\dist
    compile_ejb:
    [javac] Compiling 3 source files to D:\ejb\entity\build
    jar_ejb:
    [jar] Building jar: D:\ejb\entity\dist\Cabin.jar
    ejbc:
    [java] java.io.FileNotFoundException: META-INF/ejb-jar.xml not found in jar file
    [java]      at weblogic.ejb20.dd.xml.DDUtils.getEntry(DDUtils.java:332)
    [java]      at weblogic.ejb20.dd.xml.DDUtils.getEjbJarXml(DDUtils.java:236)
    [java]      at weblogic.ejb20.dd.xml.DDUtils.loadEJBJarDescriptorFromJarFile(DDUtils.java:151)
    [java]      at weblogic.ejb20.dd.xml.DDUtils.createDescriptorFromJarFile(DDUtils.java:139)
    [java]      at weblogic.ejb20.dd.xml.DDUtils.createDescriptorFromJarFile(DDUtils.java:130)
    [java]      at weblogic.ejbc20.runBody(ejbc20.java:338)
    [java]      at weblogic.utils.compiler.Tool.run(Tool.java:79)
    [java]      at weblogic.ejbc.main(ejbc.java:21)
    [java] ERROR: java.io.FileNotFoundException: META-INF/ejb-jar.xml not found in jar file
    compile_webapp:
    Total time: 20 second

    The Ejb jar file structure for WebLogic server:
    META-INF/ejb-jar.xml
    META-INF/weblogic-ejb-jar.xml
    META-INF/weblogic-cmp-rdbms-jar.xml
    Ejb Bean Class
    Remote interface
    Home interface

  • Re: junit test for entity beans ... ejb 3.0

    I'm confused. I'm trying to test my entity bean.
    I have:
    - an entity bean
    - a stateless session bean for accessing the entity bean (facade)
    - an interface for accessing the the stateless bean
    And I'm trying to write a JUnit test class to test this bean. However, I am uncertain as to how to test this (I'm new to EJB 3.0, JBoss and Eclipse).
    What would the JUnit test look like? I'm confused as to whether or not I should be injecting the interface/bean/what???
    I've tried several variations. I either get "NameNotFound" - not bound exceptions or Null pointer exceptions.
    What would the @EJB syntax look like or how would I do it through the context?
    For Example:
    @EJB private TestFacade myTest; //interface to stateless bean ?
    OR
    InitialContext ctx = new InitialContext();
    TestResultFacadeBean myTest = (TestResultFacadeBean) ctx.lookup("localTest");
    I'm confused at to which method I should be using and what object I should be accessing. If I could get either one to work, I'd be happy. :)
    How do I ensure my bean is deployed to the container? What do I need to do?
    If anyone has a simple example or explanation as to which method I should use and how to use it, I'd be very grateful.
    Thanks very much,
    LisaD

    OK, you need to have several layers of testing.
    Layer 0. Test the entity beans are deployable (more on this later). Basically, you need to know that all your annotations work. Things to watch out for are multiple @Id fields in one class or @EmbeddedID or @IdClass in conjuction with @ManyToOne, @ManyToMany, @OneToMany, @OneToOne and fun with @JoinTable, @JoinColumn and @JoinColumns. Once you know how these are supposed to work with the spec, it's not too bad to write it correctly each time. But there are some gotchas that will break things later on.
    Layer 1. Do the functions in the classes that don't depend on annotations work as expected. Typically, this is just going to be the getters and setters in your entity classes. Of course JUnit best practice says we don't bother testing functions that look like:
    public T getX() {
    return this.x;
    or
    public void setX(T x) {
    this.x = x;
    as there is nothing that can go wrong with them. So in that case, your level 1 tests will just be initial values specified from constructors and verifying that the non-get/set pairs work, and that the getters you have tagged @Transient work (because you've likely put some logic in them)
    Layer 2. Test the session bean methods that don't require injection to work.
    Layer 3. Test the session bean methods that require injection (Mock Objects). Simulate the injection for yourself, injecting Mock Objects for the entity manager. Then you can confirm that the correct methods are being called in the correct sequences, etc.
    [Note this may require some skill in designing the mock.  I'm working on developing my own entitymanager mock, and if it looks usefull I'll release it to the world.
    Layer 4. Test the session bean methods that require injection (Real entity manager) (See Layer 0)
    For this you will need an out of container persistence implementation.  Currently Hibernate and Glassfish provide beta versions.  You will need a different persistence.xml file that lists all the entities.  You will have to use reflection to inject the entity manager(s) that you create from an entity manager factory unless you provide a constructor that takes an EntityManager as a parameter.  You may need to use reflection to call any @PostConstruct method if you made it private.
    Layer 5. Navigate the relationships in the objects returned from Layer 4 using a database that has been loaded with test data.
    I am currently using Layers 0, 1, 2 & 4 to test my session beans and entity beans.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • IsDirty or isModified flag for Entity Beans

    I've been reading a lot of conflicting information on the use of a isModified boolean in Entity Beans. Is creating a modified boolean recommended for BMPs? Or CMPs? Or both? I am doing a BMP, and wondering if it will really buy me much performance-wise to add this logic to my ejbStore() method. Thoughts?
    Thanks,
    Ceily Turner

    Greetings,
    I've been reading a lot of conflicting information on
    the use of a isModified boolean in Entity Beans. IsAre you sure all this information was presented in the same contexts? I'm guesing the apparent conflict was only perceptual and without regard for BMP in one case and CMP in [the /an]other...
    creating a modified boolean recommended for BMPs? OrDefinitely! The container will call your bean's ejbStore method (sometime) after a call to its business method(s) to ensure its state is synchronized back to the resource. However, in a BMP bean, the container has no way of knowing whether the business method(s) actually modified your bean's state, making the call to ejbStore a "blind call". Additionally, business method calls are not the only triggers to calling ejbStore - transaction COMMIT (regardless if your bean was an active participant in the transaction), and passivation being among them, as well as "at any time within the container's discretion". Though, precisely when and how often the spec. leaves to the "vendor's disrection". With all these factors at play, "blindly" hitting the resource is a sure-fire way to degrade the performance of your beans and, consequently, the application(s) which they are a part. Make your synchronization code "smart" - use a 'dirty flag'.
    CMPs? Or both? I am doing a BMP, and wondering if itIn CMP, the container has more direct knowledge of the bean's state fields and, therefore, should know whether an actual update to the resource is needed - this is especially true for EJB 2.0. Of course, this depends on the vendor's implementation (coders) to be "smart" on the bean coder's behalf. In any event, the container has absolute control over bean synchronization, and ejbStore is relegated to being a pre-processor, in CMP, so using a 'dirty flag' here will gain you absolutely nothing!
    will really buy me much performance-wise to add this
    logic to my ejbStore() method. Thoughts?Refer back to the above. :)
    Thanks,
    Ceily TurnerRegards,
    Tony "Vee Schade" Cook

  • Object attribute for Entity Bean?

    Can I have an Object type attribute in an Entity Bean that must be mapped to a database. This Object will then only contain text attributes. For example,
    class UserBean {
    String name;
    Address address;
    class Address {
    String street;
    String streetnumber;
    In other words: Can I use EJB's to provide the same facility that an Object-Oriented Database provides?

    Providing you are not worried about referential integrity, CMP will do this automatically.

  • Type of Serialized Object for Entity Bean

    Hi,
    I develop a container managed persistence entity bean. I want to persist an object that is serializable into a database column. My database column type is a Blob. I wonder what is the type of a field in my entity bean? Please help. Thanks in advance.
    Cheers,
    Paul Ngo

    Providing you are not worried about referential integrity, CMP will do this automatically.

  • Help needed for entity bean

    i have this entity bean tat creates a new row in a mysql database... and using mysql query browser i see the record... but when using the bean to retrieve, it gives finderexception... i have to undeploy + redeploy to be able to retrieve the record... y is tat so?
    how can i solve this..? i'm using jboss.

    some parts of my code is listed as below...
    private static final String insertStatement = "INSERT INTO cards (cardid, imageid, musicid, message, createdby, recipientEmail, createddate) VALUES (?, ?, ?, ?, ?, ?, ?)";
    private static final String updateStatement = "UPDATE cards SET imageid=?, musicId=?, message=?, createdby=?, recipientEmail=?, createddate=? WHERE cardid=?";
    private static final String deleteStatement = "DELETE FROM cards WHERE cardid=?";
    private static final String findByPKStatement = "SELECT imageid, musicid, message, createdby, recipientEmail, createddate FROM cards WHERE cardid = ?";
    public String ejbCreate(String cardID, String imageID, String musicID, String message, String createdBy, String recipientEmail, java.sql.Date createdTime) throws CreateException {
    try {
    getDatabaseConnection();
    ps = connection.prepareStatement(insertStatement);
    ps.setString(1, cardID);
    ps.setString(2, imageID);
    ps.setString(3, musicID);
    ps.setString(4, message);
    ps.setString(5, createdBy);
    ps.setString(6, recipientEmail);
    ps.setDate(7, createdTime);
    if (ps.executeUpdate() != 1) {
    throw new CreateException("Failed to insert new record");
    } catch (SQLException e) {
    throw new CreateException(e.getMessage());
    } catch (Exception e) {
    } finally {
    try {
    ps.close();
    connection.close();
    } catch (Exception e) { }
    return cardID;
    public String ejbFindByPrimaryKey(String cardID) throws FinderException {       
    try {
    getDatabaseConnection();
    ps = connection.prepareStatement(findByPKStatement);
    ps.setString(1, cardID);
    ps.executeQuery();
    ResultSet rs = ps.getResultSet();
    if (rs.next()) {
    this.cardID = cardID;
    imageID = new String(rs.getString(1));
    musicID = new String(rs.getString(2));
    message = new String(rs.getString(3));
    createdBy = new String(rs.getString(4));
    recipientEmail = new String(rs.getString(5));
    createdTime = rs.getDate(6);
    } else {
    throw new FinderException("Failed to select this Primary Key");
    } catch (SQLException e) {
    throw new FinderException(e.getMessage());
    } catch (Exception e) {
    } finally {
    try {
    ps.close();
    connection.close();
    } catch (Exception e) { }
    return cardID;
    private void getDatabaseConnection() throws NamingException, SQLException {
    InitialContext ctx = new InitialContext();
    String connectionURL = "jdbc:mysql://localhost:3306/card";
    try {
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    connection = DriverManager.getConnection(connectionURL, "root", "123");
    catch (Exception e) {     }
    }

  • Which WebLogic XDoclet Properties to set for Entity Beans

    I have no documentation about howto set the WebLogic XDoclet properties (in a EJB Project).
    The Entity Beans used by me, are CMP's accessing an Oracle Data Source (allready setup by me in the WebLogic console).
    If someone knows documentation about this, or some example of a CMP (with @weblogic tags) that is backed by an Oracle table, I will appreciate that very much

    Hi ,
    Go through the following link,In that you will find the weblogic tags and will get some needfull information on this issue.
    http://dev2dev.bea.com/pub/a/2002/03/243.html
    Regards
    Anilkumar kari

  • Creation of package structure for ABAP proxy scenario

    Hi All,
    I have a doubt on package structure used for ABAP proxy scenario. What is the specific reason to create a four level package structure? Can some one please explain? Thanks in advance.
    Regards,
    Sudheer.

    Hi Sudheer,
    Can you pls clarify what do you mean by 'four level package structure' ?
    Are you referring to the ABAP structures that get created during creating the proxy by SPROXY transaction ? These structures get automatically created. We simply have to write the code using these structures.
    Or do you mean the 'package' which is mandatory to create a transportable ABAP object ? i.e. transport from Development to Staging and then Production.
    Regards,

  • Deploying BMP Entity Bean with primary key calss

    Hi,
    I am using EJB 2.0 with and websphere studio 5.0 and database is sql server 2000.
    My BMP Entity bean has a primary key class.From my client I am invoking the Entity Bean by calling it's findbyprimarykey method.
    The home interface of my findbyprimarykey method returns a class of type Remote.But in the Entity Bean class,the return type is the primarykey class type.
    My problem is invoking this findbyprimarykey from the client to get the remote interface so that the other business methods of the entity bean can be called.
    The control goes into the ejbFindbyPrimaryKey but when it is returing from the Entity Bean class,it gives a remote exception (as the return type in Entity Bean class and Home interface are different for the findbyprimarykey method).
    I think that somewhere in the deployment decriptor in my websphere,i have to specify the primarykey class type,which i am missing out and hence getting the error.
    Please help me out with your advice and solution.
    Thanks
    Rahul Priyadarshi

    Hi,
    Sorry to disturb you again.
    Even my code is also almost the same....i am pasting the code below...Please go through it and let me know if I have made any mistake..
    EditVendorEntityBean.....(Bean Class)
    package code.beans.EditVendor;
    import code.beans.dataAccess.*;
    import javax.ejb.CreateException;
    import javax.ejb.RemoveException;
    import javax.ejb.EntityBean;
    import javax.ejb.EntityContext;
    import javax.ejb.EJBException;
    import javax.ejb.FinderException;
    import javax.ejb.ObjectNotFoundException;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import java.sql.*;
    import javax.sql.*;
    import java.util.*;
    * Bean implementation class for Enterprise Bean: EditVendorEntity
    public class EditVendorEntityBean implements javax.ejb.EntityBean {
         private static Hashtable dataSources = new Hashtable();
         private String username;
    private int Vendor_ID;
    private int Category_Id;
    private String Category_Name;
    private String Vendor_Name;
    private String Vendor_Address1;
    private String Vendor_Address2;
    private String Contact_Name;
    private String Home_Phone;
    private String Work_Phone;
    private String email;
    private String faxno;
    private String userloginname;
    private boolean dirtyFlag = false;
    private EntityContext context;
    private static final String DS_NAME = "jdbc/spiPOPS";
    Connection con = null;
    Statement stmt = null;
    PreparedStatement st = null;
    ResultSet res = null;
         //***********************Business Methods*********************
    // Begin of Busines Methods
    public void setData (String[] catname, String vendorname,String vendadd1,String vendadd2,String vendcontact,String venoff,String venres,String mailid,String venfax) {
              System.out.println("in setData where Vendor Id= "+ Vendor_ID);
                   boolean status=false;
                   boolean existing=false;
                   ArrayList cat=new ArrayList();
                   try
                        cat=getcategorylist(this.Vendor_ID);
                   catch(SQLException e)
                        System.out.println("Could not get category list");
                   System.out.println("Size of cat array -->" + cat.size() + " and string array size -->" + catname.length);
                   if(catname.length>0)
                        //Removing unwanted vendor categories for a particular vendor id
                        for(int i=0;i<cat.size();i++)
                                  existing=false;
                                  String tempdata=(String)cat.get(i);
                                  for(int j=0;j<catname.length;j++)
                                       if(tempdata.equals(catname[j]))
                                            existing=true;
                                  if(!existing)
                                       try
                                            delvencat(this.Vendor_ID,tempdata.trim());
                                       catch(SQLException e)
                                            System.out.println("Could not delete record in POPS_VENDOR_CATEGORY for -->" + tempdata);
                   //Adding new vendor categories for a particular vendor
                        try
                                  for(int i=0;i<catname.length;i++)
                                       status=false;
                                       String strcat=catname;
                                       status=checkcat(this.Vendor_ID,strcat.trim());
                                       if(!status)
                                            insertvencat(this.Vendor_ID,strcat.trim());
                        catch(SQLException e)
                                  System.out.println("Could not insert or select from POPS_VENDOR_CATEGORY table");
                   this.Vendor_Name          =vendorname;
              this.Vendor_Address1     =vendadd1;
              this.Vendor_Address2     =vendadd2;
              this.Contact_Name          =vendcontact;
              this.Work_Phone               =venoff;
              this.Home_Phone               =venres;
              this.email                    =mailid;
              this.faxno                    =venfax;
                   dirtyFlag = true;
                   System.out.println("Leaving set data method");
    public Vector getData() {
         Vector vctRec=new Vector();
         ArrayList arrdatas = new ArrayList();
         arrdatas.add(""+this.Vendor_ID);
         arrdatas.add(this.Vendor_Name);
         arrdatas.add(this.Vendor_Address1);
         arrdatas.add(this.Vendor_Address2);
         arrdatas.add(this.Contact_Name);
         arrdatas.add(this.Work_Phone);
         arrdatas.add(this.Home_Phone);
         arrdatas.add(this.email);
         arrdatas.add(this.faxno);
         vctRec.addElement(arrdatas);
         ArrayList cat=new ArrayList();
              try
              System.out.println("Calling getcategorylist from getdata with vendorid-->" + this.Vendor_ID);
              cat          = getcategorylist(this.Vendor_ID);
         catch(SQLException e)
                   System.out.println("Could not get datas for category list");
         vctRec.addElement(cat);
         ArrayList allcats=new ArrayList();
         try
                        allcats          = getallcategorylist();
              catch(SQLException e)
                        System.out.println("Could not get datas for category list");
         vctRec.addElement(allcats);
              dirtyFlag = false;
         System.out.println("Before return statement in getdata with vector size -->" + vctRec.size());
              return vctRec;
    // End of Business Methods
    //**************************Entity Bean Methods*******************************
         * ejbActivate
         public void ejbActivate() {
              Vendor_ID = Integer.parseInt((String)context.getPrimaryKey());
         System.out.println("Inside ejbActivate Vendor_ID-->"+ Vendor_ID);
         * ejbLoad
         public void ejbLoad() {
              System.out.println("Inside ejbLoad ********" );
    try {
    loadRow();
    }catch (Exception ex) {
              System.out.println("Failed in loadRow()");
    throw new EJBException("ejbLoad: " +
    ex.getMessage());
         * ejbPassivate
         public void ejbPassivate() {
         System.out.println("Inside ejbPassivate " );
    Vendor_ID = 0;
         * ejbRemove
         public void ejbRemove() throws javax.ejb.RemoveException {
              //Empty Method
         * ejbStore
         public void ejbStore() {
    System.out.println("Inside ejbStore " );
    try {
    storeRow();
    }catch (Exception ex) {
              System.out.println("Exception thrown in storeRow" + ex.getMessage());
    throw new EJBException("ejbLoad: " +
    ex.getMessage());
         * getEntityContext
         public javax.ejb.EntityContext getEntityContext() {
              return context;
         * setEntityContext
         public void setEntityContext(javax.ejb.EntityContext ctx) {
              System.out.println("Inside setEntityContext " );
    try{
         con = getConnection(DS_NAME);
         System.out.println("DB Connection Created!!");
    catch(Exception e){
    this.context = ctx;
         * unsetEntityContext
         public void unsetEntityContext() {
    System.out.println("Inside unsetEntityContext " );
    closeDbConnection(con, res, st);
    this.context = null;
         * ejbCreate
         //code.beans.EditVendor.EditVendorEntityKey
         public code.beans.EditVendor.EditVendorEntityKey ejbCreate(String vendorid)
              throws javax.ejb.CreateException {          
              return new EditVendorEntityKey(vendorid);
              //return null;
         * ejbPostCreate
         public void ejbPostCreate(String vendorid) throws javax.ejb.CreateException {
              //Empty
         * ejbFindByPrimaryKey
         //code.beans.EditVendor.EditVendorEntityKey
         public code.beans.EditVendor.EditVendorEntityKey ejbFindByPrimaryKey(
              code.beans.EditVendor.EditVendorEntityKey primaryKey)
              throws javax.ejb.FinderException {
    try {
    if(selectByPrimaryKey(Integer.parseInt(primaryKey.getVendorId()))) {
              System.out.println("Leaving the findbyprimarykey method from the entity bean");
         return primaryKey;
         //return null;
    }else {
         throw new ObjectNotFoundException
         ("Row for id " + primaryKey + " not found.");
    }catch (Exception ex) {
    throw new EJBException("EXCEPTION IN ejbFindByPrimaryKey :- " + ex.getMessage());
         /*********************** Database Utility Routines *************************/
    private boolean selectByPrimaryKey(int priKey)
    throws SQLException {
         System.out.println("inside selectByPrimaryKey for primary key " + priKey);
    String queryStr ="SELECT VENDOR_ID FROM POPS_VENDOR WHERE VENDOR_ID = " + priKey;
    System.out.println("in selectByPrimaryKey where queryString is: "+ queryStr);
              stmt = con.createStatement();
    ResultSet result = stmt.executeQuery(queryStr);
    if(!result.next()) {
    stmt.close();
         System.out.println("Did not find "+priKey);
    return false;
    else { //Found the primaryKey
    Vendor_ID = result.getInt("VENDOR_ID");
    stmt.close();
    return true;
    private void loadRow() throws SQLException {
              System.out.println("inside loadRow ...");
              stmt = con.createStatement();
              String queryStr = "SELECT VENDOR_NAME,VENDOR_ADDRESS1,VENDOR_ADDRESS2,CONTACT_NAME,HOME_PHONE,WORK_PHONE,EMAIL_ID,FAX_NO " +
                                  "FROM POPS_VENDOR WHERE VENDOR_ID=" + Vendor_ID;
              System.out.println("Inside loadRow()***********"+queryStr);
              ResultSet result = stmt.executeQuery(queryStr);
              ArrayList catadatas=new ArrayList();
         if(!result.next())
         throw new SQLException("No record for primary key" + Vendor_ID);
              this.Vendor_ID               =Vendor_ID;
                        this.Vendor_Name          =result.getString("VENDOR_NAME");
                        this.Vendor_Address1     =result.getString("VENDOR_ADDRESS1");
                        this.Vendor_Address2     =result.getString("VENDOR_ADDRESS2");
                        this.Contact_Name          =result.getString("CONTACT_NAME");
                        this.Home_Phone               =result.getString("HOME_PHONE");
                        this.Work_Phone               =result.getString("WORK_PHONE");
                        this.email                    =result.getString("EMAIL_ID");
                        this.faxno                    =result.getString("FAX_NO");
                             System.out.println("Leaving loadrow method with loaded datas for vendor -->" + Vendor_ID);
                             stmt.close();
    private ArrayList getcategorylist(int vendor) throws SQLException{
              String queryStr ="SELECT DISTINCT(VENDOR_CAT) FROM POPS_VENDOR_CATEGORY WHERE VENDOR_ID=" + vendor;
              System.out.println("Query for the cat list --> " + queryStr);
              stmt = con.createStatement();
              ResultSet result = stmt.executeQuery(queryStr);
              ArrayList catdatas=new ArrayList();
    try{
                   while(result.next())
                        catdatas.add(result.getString("VENDOR_CAT"));
              catch (SQLException e){
                   stmt.close();
                   System.out.println("Could not retrieve datas for Category list");
              stmt.close();
              System.out.println("size off array for cat -->" + catdatas.size() + " and datas ->" + catdatas);
              return catdatas;
         private ArrayList getallcategorylist() throws SQLException{
                   //String queryStr ="SELECT DISTINCT(VENDOR_CAT) FROM POPS_VENDOR_CATEGORY";
                   StringBuffer strquery=new StringBuffer(20);
                   strquery.append("SELECT DISTINCT(CATEGORY_NAME) FROM POPS_CATEGORY");
                   stmt = con.createStatement();
                   //ResultSet result = stmt.executeQuery(queryStr);
                   ResultSet result = stmt.executeQuery(strquery.toString());
                   ArrayList catdatas=new ArrayList();
                   try{
                        while(result.next())
                                  //catdatas.add(result.getString("VENDOR_CAT"));
                                  catdatas.add(result.getString("CATEGORY_NAME"));
                   catch (SQLException e){
                             stmt.close();
                             System.out.println("Could not retrieve datas for All Category list");
                   stmt.close();
                   return catdatas;
         private void delvencat(int vendor,String vencat) throws SQLException {
              int update=-1;
              stmt = con.createStatement();
              String queryStr ="DELETE FROM POPS_VENDOR_CATEGORY WHERE VENDOR_ID = " + vendor + " AND VENDOR_CAT = '" + vencat.toUpperCase() + "'";
              System.out.println("Delete query --> " + queryStr);
              update= stmt.executeUpdate(queryStr);
              if(update!=1)
                   System.out.println("Did not find data to delete");
              stmt.close();
         private void insertvencat(int vendor,String vencat) throws SQLException {
              int update=-1;
              String queryStr ="INSERT INTO POPS_VENDOR_CATEGORY(VENDOR_ID,VENDOR_CAT)" +
                                  " VALUES(" + vendor +",'" + vencat + "')";
              System.out.println("Insert query --> " + queryStr);
              stmt = con.createStatement();
              update=stmt.executeUpdate(queryStr);
              if(update!=1)
                   System.out.println("Could not insert records in the database");
              stmt.close();
         private boolean checkcat(int vendor,String catven) throws SQLException {
              boolean datastatus=false;
              String queryStr ="SELECT VENDOR_ID FROM POPS_VENDOR_CATEGORY WHERE VENDOR_ID = " + vendor + " AND VENDOR_CAT = '" + catven.toUpperCase() + "'";
              stmt = con.createStatement();
              ResultSet result = stmt.executeQuery(queryStr);
              datastatus=result.next();
              stmt.close();
              return datastatus;
    private void storeRow() throws SQLException {
                   System.out.println("Inside ejb store");
         if (!dirtyFlag) {
         System.out.println("Skipping the UPDATE because object is not dirty");
         return;
         CallableStatement cs=null;
    try{
                        cs = con.prepareCall("EXEC POPS_VENDOR_UPDATE " + this.Vendor_ID + ",'" + this.Vendor_Name + "','" + this.Vendor_Address1 + "','" + this.Vendor_Address2 + "','" + this.Contact_Name + "','" + this.Work_Phone + "','" + this.Home_Phone + "','" + this.email + "','" + this.faxno +"'");
                        System.out.println("\n\n SQL Statement : \n " + "EXEC POPS_VENDOR_UPDATE " + this.Vendor_ID + ",'" + this.Vendor_Name + "','" + this.Vendor_Address1 + "','" + this.Vendor_Address2 + "','" + this.Contact_Name + "','" + this.Work_Phone + "','" + this.Home_Phone + "','" + this.email + "','" + this.faxno +"'");
                        cs.executeUpdate();
              catch (SQLException e){
                        cs.close();
                        System.out.     println("\n\n Error in calling stored procedure POPS_INSERT_NEW_REQUEST \n\n"+ e.getMessage() + "\n\n");
              cs.close();
              dirtyFlag = false;
         private Connection getConnection(String dbName) throws SQLException
              String configuredDataSourceName = null;
              if (dbName == null) {
                   System.out.println("Attemp to get connection failed. The requested database name is null");
              DataSource dbSource = getDataSource(dbName);
              return dbSource.getConnection();
         private DataSource getDataSource(String dbName)
              // looking from cache;
              DataSource dbSource = (DataSource) dataSources.get(dbName);
              if (dbSource == null) { //we need to find it from JNDI
                   try {
                        Context ic = new InitialContext();
                        dbSource = (DataSource) ic.lookup(dbName);
                        dataSources.put(dbName, dbSource);
                   }catch (NamingException e){
              return dbSource;
         * User calls this function to safely close an connection
         * @param connt The connection a datasource
         * @param rs The resulSet inside this connection
         * @param statement The statement associate with this connection
         private void closeDbConnection(Connection cont,ResultSet rs,Statement statement)
              if (rs != null)
              try {
                        rs.close();
                   } catch (SQLException ignored) {
                        ignored.printStackTrace();
              if (statement != null)
                   try {
                        statement.close();
                   } catch (SQLException ignored) {
                        ignored.printStackTrace();
              if (cont != null)
                   try {
                        cont.close();
                   } catch (SQLException ignored) {
                        ignored.printStackTrace();
         } //closeDbConnection
    EditVendorEntity (Remote Interface)
    package code.beans.EditVendor;
    import javax.ejb.EJBObject;
    import java.rmi.RemoteException;
    import java.util.*;
    * Remote interface for Enterprise Bean: EditVendorEntity
    public interface EditVendorEntity extends javax.ejb.EJBObject {
         public void setData (String[] catname, String vendorname,String vendadd1,String vendadd2,String vendcontact,String venoff,String venres,String mailid,String venfax)
                   throws RemoteException;
    public Vector getData() throws RemoteException;
    EditVendorEntityHome (Home Interface)
    package code.beans.EditVendor;
    import java.rmi.RemoteException;
    import javax.ejb.CreateException;
    import javax.ejb.FinderException;
    import javax.ejb.DuplicateKeyException;
    import javax.ejb.EJBHome;
    import java.util.*;
    * Home interface for Enterprise Bean: EditVendorEntity
    public interface EditVendorEntityHome extends javax.ejb.EJBHome {
         * Creates an instance from a key for Entity Bean: EditVendorEntity
         public code.beans.EditVendor.EditVendorEntity create(String vendorid)
              throws javax.ejb.CreateException, java.rmi.RemoteException;
         * Finds an instance using a key for Entity Bean: EditVendorEntity
         public code.beans.EditVendor.EditVendorEntity findByPrimaryKey(
              code.beans.EditVendor.EditVendorEntityKey Vendor_ID)
              throws javax.ejb.FinderException, java.rmi.RemoteException;
    EditVendorEntityKey (Primary Key Class)
    package code.beans.EditVendor;
    * Key class for Entity Bean: EditVendorEntity
    public class EditVendorEntityKey implements java.io.Serializable {
         static final long serialVersionUID = 3206093459760846163L;
         public String primkey;
         * Creates an empty key for Entity Bean: EditVendorEntity
         public EditVendorEntityKey() {  }
         public EditVendorEntityKey(String primarykey) {     
              this.primkey=primarykey;
         public String getVendorId() {
    return primkey;
         * Returns true if both keys are equal.
         public boolean equals(java.lang.Object otherKey) {
              if (otherKey instanceof code.beans.EditVendor.EditVendorEntityKey) {
                   code.beans.EditVendor.EditVendorEntityKey o =
                        (code.beans.EditVendor.EditVendorEntityKey) otherKey;
                   return (primkey.equals(otherKey));
              return false;
         * Returns the hash code for the key.
         public int hashCode() {
              return (primkey.hashCode());
    Please go through and give me your comments and solution...
    Thanks in advance
    Rahul

Maybe you are looking for

  • Some pages in japanees or chiness.

    Hello, i Installed some fonts in fontbook, and after that only some pages(like hotmail) turn to be in a oriental lenguaje. That includes the fill sapeces where I write and other letters, not al of them, I cheked my safari preferences and the booth ar

  • Cannot able to save Excel 2013 file in Sharepoint 2007 document library

    Dear All, We have SharePoint 2007 intranet portal where in we have teamplace created for internal users to collaborate on documents. Now we are having issues when using uploads Excel 2013 or Excel 2010 file on document library and try to edit the doc

  • Two actions on same day

    hi, We have requirement where we need to run the two actions on same day Hiring actions Change in pay action In hiring action basic pay has to come as mention in pay scale group then they want to run one more actions called change in pay on same day

  • Can't start Firefox

    I can't start Firefox. I try double click, right click->open or press enter but nothing work. Then I look at processes in task manager, don't have firefox.exe there. And there isn't any error message. I already try restart computer or reinstall firef

  • DECODE syntax

    Hello, I wanted to use the DECODE function for an insert into a database table. It should work like this: If value1 is a, b, or c then value2 should be 1 and if value1 is d, then value2 should be 2. I know I can code it like this: SELECT DECODE (valu