EJB design for dynamically created tables

Discussions

EJB design: EJB design for dynamically created tables

  1. EJB design for dynamically created tables (7 messages)

    Hi,

          I have a design for an application with will be dynamically creating the structure of a table and then later on, we will populate it with the appropriate information. My question is how do I code the Entity Beans and Session Beans to access this table? Is this even possible to do?

    thanks!
    maira :-)
  2. just out of curiosity,
    why do you want to create tables dynamically?

    to answer your question,
    you can write beans that access these dynamic tables, then can simply use the catalog to lookup the meta data about the tables.

    Take a look at java.sql.Connection.getMetaData()

    Filip
  3. Well, it's part of the design for the application. We are tracking attributes that can be different from one client to another.

    I'll take a look at what you suggested. Thanks for replying! I wasn't sure where to start.

    maira :-)
  4. Filip,

          I took a look at what you suggested, but I'm still a little confused about how I should code the Entity and Session beans to access this information. Can you point me to any examples anywhere on the web on how to do this?

    thanks!
    maira :-)
  5. Take a look at Sun's JDBC tutorial for info on how to access the MetaData. Ideally you would want to use this in your ejbLoad/Store/Create/Remove methods.

    I've done something similar where I encapsulated all this metadata stuff into my own stateful session bean. I bound an instance (Handle) of that bean to the JNDI repository for my application server, and would query it whenever I was generating an SQL call to find out what tables were available / what fields were there. Worked like a charm.

  6. Have you consider using a meta data schema on the database?

    With such schema you can store new objects and new object's attributes on the fly, without modifying the schema.

    Just a thought.

  7. A metadata schema? Can you tell me more about that or point me to a source of information?

    Also, I'm assuming that the suggestion which Filip and Stu have posted indicate that the coding to deal with accessing the dynamically generated tables is in the session beans since the entity beans assume the structure is there in the database.

    I hope I'm not being ignorant here! :-) I really do appreciate all of the help that I'm getting on this.

    thanks!
    maira :-)
  8. Hi Maira,

    Try using XML in a combination with the EJB Session Bean that parses XML file containg your table definition, this way you can have file alterable table schema structure, without having to recompile, I dont suggest you do this for everything, but for the very dynamic parts only. But in essence you should really avoid creating tables on the fly, but maybe you have a real need, and I would look at the XML approach.

    Let me know if you want further clarification.

    Emad J. Benjamin.