• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Entity Bean - XML view

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyona, it's my first post here so...
Good Morning
The idea is to exchange data between ejb's and ejb<->jsp, in XML format.
Questions are:
- can I have nonpersistant field in entity bean which will contain xml view of this bean?
- I'd like this field be common for all entity beans in application (I don't excately understand how app. server manages multiple instances of entity bean) could it be static field?
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Second question first. No static objects in EJBs unless they are "final"! The EJB itself and its contents should be considered as distinct entities. When you need an EJB for specific data, the container creates a new EJB, pulls an idle one from cache, or selects a least-recently-used EJB (in this case, causing its contents to be written to persistent storage -- "paged out", if you like). The new, "blank" EJB is then filled in with the data. So necessarily, one EJB must be interchangable with any other of the same class.
EJBs run in a multi-threaded environment and depending on your selected transaction mode this could be hazardous to static data, but for a more complete and accurate description of why you shouldn't even consider this, I recommend you read the "thou shalt not" section of the EJB spec - it gives the reasons why.
I think you're also confused about what "static" means. In Java, static means that the item is attached to the class rather than to an instance of the class, so if you set "price" as a static field to "$15.00", it would be $15.00 for all of that kind of object. I think what you wanted was "final", which means that the value is constant and will never change.
[ February 18, 2002: Message edited by: Tim Holloway ]
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
konrad
Don't really understand how you are expecting this XML field to work, don't think it can be Static as the field is instance specific?
Do you only want to use it as a performance cache? If so I'd test whether it is required before attempting it.
Would it not be easier to just have a method that returns the xml or alternatively a generic session bean that you could pass an entity bean to and it would return the xml.
I also expect people have already done this sort of thing before I'd do a trawl of the web\newsgroups to see if you can find anything. Also check out web services and SOAP interfaces for EJBs as that is creating an XML interface.
There are no problems having non-persistent field in an entity bean. If you are using BMP then you are in charge of persistence anyway, if you use CMP don't list it in the CMP fields in the descriptor. However you need to be careful, especially concerning passivate\activate.
Phil
 
konrad hoszowski
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your help
I know that my proposition to use static field is a bit wired.
In prev version of application I was useing method that was generating and returning XML view of bean. (CMP1.1)
New version is to be reimplemented as EJB2.0. I wander if it could be possible to cache XML but I don;t know how to synchronize this field trough all entity instances. That why I was thinking about static field not final.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic