Entity bean and session bean accessing the same data.


EJB design: Entity bean and session bean accessing the same data.

  1. try this one !

    How will a container handle this design ?

    I have and entity bean called "Article" that is made up of smaller parts e.g. images, text

    The images and text objects can be classed as dependants of an Article entity bean in the sense that they are only ever viewable though a public view (e.g. the website) when they are part of an article EB. So when I load an "Article" EB I will also load all the images and text objects associated with it and store them as members of the entity bean.

    the catch....

    However the images and text objects are also independent of an Article in the sense that an image or text object can exist without being associated with an article. However these objects are only viewable from a backend admin interface where they can be created,updated and deleted. Also the same image or text object can be associated with more then one article.

    "the text or image have a many to many relationship with an Article"
    ONE image can be in MANY articles
    ONE article can have MANY images

    Although the images and text are independent of an article EB I consider them too fine grain to be entity beans themselves. So to created,updated and deleted the image and text objects I intend to create a Stateless Session bean that is used to access the database tables that contain these objects.

    so my question is. What happens if I am updating an image (or text) row via the Stateless Session bean and an Article Entity bean that references this image is trying to read this data at the same time. Will the database put a lock on this data so that the entity bean cannot read the data until the Session bean has updated the table or will it all mess up. What will happen ?


    Regards Peter
  2. At any point of time only one thread will be active so when you try to read the data through entity bean and it makes the bean activate and the value will be managed by the container and if you try to modify the data through stateless it will modify but when the entity try to passivate it wll overwrite the value with old value and the value written by stateless is lost
  3. ha sorry

    I for got to add that the Article Entity bean is a BMP and that it read-only, well as far as the images and text parts are concerned.

    For example. In the ejbStore() method i will not write any information about the Images or Text to the the database.

    I will only ever read is data via the ejbLoad() method.

  4. why images and texts are too fine grained to be entity beans themselves?
  5. if you set the isolation level to READ_COMITTED for the EB, then you will not face the problem.
    but if the entity bean is in the memory (cached) and stateless session bean updates the data in the database, you might be holding dirty data.(is there a way for read only beans to refresh the data once in x minutes!)
  6. Hi,
    I'm new to this forum.
    Is there any possibility to remove the entity instatnces from the server.It should not call the ejbRemove ,which will remove the data from the database.
    To put it very clear.I'm having Customer details in an entity bean.Some time,thro a session bean,I'll change the status of group of customers to .. say Active .To avoid loading many entities and setting the status,I do it thro a stateless bean.Now,the problem is,the cached eb's will have dirty data.Is there any ways to remove those instances from the server without removing the data ?.