Re: Invalidating an Entity bean

2000-10-12 Thread Nick Newman

Hi Peter,

I'm not claiming guru-hood, but as far as I know you CAN'T do that cleanly.
 My thoughts on your best options are:

1) Tell Orion that the entity beans do not have exclusive write-access to
the database by setting exclusive-write-access="false" in the
orion-ejb-jar.xml (which is orion-specific).  I believe this causes the
data to be re-read at the start of every transaction.

2) Re-write your session bean to makes its database changes through the
entity beans rather than through direct JDBC.

Nick

At 12:02 PM 10/12/00 +0100, you wrote:
Hi gurus

How do I do this cleanly.

I have and Entity that has attributes A,B,C and D. These attributes are all
read from database tables.

A and B are read from Table 1
C and D are read from Table 2

So I have Entity Bean 1, this is loaded by the app server (perhaps by a
findByPrimaryKey) method. This means that Entity Bean 1 is now a cache of
the data in A,B,C and D. 

However while this entity bean is in the cache, via a session bean I change
the data of C and D in table 2. This mean that Entity Bean 1 now has dirty
data. So the question is how do I force the Entity beans to do and EJB Load.


Also the data in C and D in table 2 may be shared by N number of entity
beans so I may need to refresh N number of Entity Beans depending on which
ones are in the cache.

I only want to call EJB load for Entity beans currently in the cache and of
these I only want to call ejb load for the ones that refer to the changed
data.

Cheers Peter





RE: Invalidating an Entity bean

2000-10-12 Thread Peter Delahunty


the situation is this.

this is the current data model

I have and entity bean called "Content" this repsents 1 row in a table
called "content". The content enitity bean can have N number of images
(corresponds to n number of rows in the images table) and N number of text
blocks (corresponds to n number of rows in the text table).

However images and text blocks are independent of content. Content is only a
grouping of these assets if you like. So we get a many to many relationship.


1 content can reference many images
1 image can be referenced by many content.
(same for text)

so when a content entity bean loads up it loads into its attributes all the
data from the images and text that it references. So lets assume all this
data is now in a cache.


if i then change the data in an image or text independently of the entity
bean (perhaps by a session bean) then the data that is cached in the entity
bean is dirty (does not match what is in the database). SO how do i notify
the entity bean to refresh it's self ?


Another model you hinted on was that Image and text could be enitity beans.
They are certainly independent enities (qualify as enities). However i
consider them to be too fine grained. For example text block could be as
small as "hello this is a sentance" which is just a small string and so
wrapping this small string in an entity bean seem way too much overhead. But
the flip side is it would so the cache problem.

the session bean would do updates via the image and text beans and so they
would always contain the correct data. And content would get the data from
the image and text entity bean each time. However if the content has 50 text
block and 50 images that is 100 calls (one to each of the entity beans that
represent this data), which as you see is a major overhead

Any thoughs on how i best model this.

cheers

-Original Message-
From: Nick Newman [mailto:[EMAIL PROTECTED]]
Sent: Thursday, October 12, 2000 5:08 PM
To: Orion-Interest
Subject: Re: Invalidating an Entity bean


Hi Peter,

I'm not claiming guru-hood, but as far as I know you CAN'T do that cleanly.
 My thoughts on your best options are:

1) Tell Orion that the entity beans do not have exclusive write-access to
the database by setting exclusive-write-access="false" in the
orion-ejb-jar.xml (which is orion-specific).  I believe this causes the
data to be re-read at the start of every transaction.

2) Re-write your session bean to makes its database changes through the
entity beans rather than through direct JDBC.

Nick

At 12:02 PM 10/12/00 +0100, you wrote:
Hi gurus

How do I do this cleanly.

I have and Entity that has attributes A,B,C and D. These attributes are all
read from database tables.

A and B are read from Table 1
C and D are read from Table 2

So I have Entity Bean 1, this is loaded by the app server (perhaps by a
findByPrimaryKey) method. This means that Entity Bean 1 is now a cache of
the data in A,B,C and D. 

However while this entity bean is in the cache, via a session bean I change
the data of C and D in table 2. This mean that Entity Bean 1 now has dirty
data. So the question is how do I force the Entity beans to do and EJB
Load.


Also the data in C and D in table 2 may be shared by N number of entity
beans so I may need to refresh N number of Entity Beans depending on which
ones are in the cache.

I only want to call EJB load for Entity beans currently in the cache and of
these I only want to call ejb load for the ones that refer to the changed
data.

Cheers Peter





RE: Invalidating an Entity bean

2000-10-12 Thread Nick Newman

Sorry, but as I said, there is (as far as I know) no clean (ie. portable)
way to tell an entity bean to refresh itself.  The specs even specifically
say that an entity bean does NOT have to worry about the database being
changed "behind its back" (although you should peraps check the exact details).

I agree that separate entity beans seem to be too small.

How about using dependent objects?  If you had a big entity bean that
contained Collections of dependent objects (images and text) then changing
these dependent objects inside the bean will leave the bean in a "clean"
state.  The changes will be persisted to the DB automatically.  (EJB 2.0
would perhaps be better than EJB 1.1 for this approach).

I'll have to leave you to decide if that's really workable.  If you decide
you have to stick with direct JDBC access to write to the DB from a Session
bean, then I think you'll be stuck with non-portable solutions.

Good luck!
Nick

At 07:59 PM 10/12/00 +0100, you wrote:

the situation is this.

this is the current data model

I have and entity bean called "Content" this repsents 1 row in a table
called "content". The content enitity bean can have N number of images
(corresponds to n number of rows in the images table) and N number of text
blocks (corresponds to n number of rows in the text table).

However images and text blocks are independent of content. Content is only a
grouping of these assets if you like. So we get a many to many relationship.


1 content can reference many images
1 image can be referenced by many content.
(same for text)

so when a content entity bean loads up it loads into its attributes all the
data from the images and text that it references. So lets assume all this
data is now in a cache.


if i then change the data in an image or text independently of the entity
bean (perhaps by a session bean) then the data that is cached in the entity
bean is dirty (does not match what is in the database). SO how do i notify
the entity bean to refresh it's self ?


Another model you hinted on was that Image and text could be enitity beans.
They are certainly independent enities (qualify as enities). However i
consider them to be too fine grained. For example text block could be as
small as "hello this is a sentance" which is just a small string and so
wrapping this small string in an entity bean seem way too much overhead. But
the flip side is it would so the cache problem.

the session bean would do updates via the image and text beans and so they
would always contain the correct data. And content would get the data from
the image and text entity bean each time. However if the content has 50 text
block and 50 images that is 100 calls (one to each of the entity beans that
represent this data), which as you see is a major overhead

Any thoughs on how i best model this.

cheers

-Original Message-
From: Nick Newman [mailto:[EMAIL PROTECTED]]
Sent: Thursday, October 12, 2000 5:08 PM
To: Orion-Interest
Subject: Re: Invalidating an Entity bean


Hi Peter,

I'm not claiming guru-hood, but as far as I know you CAN'T do that cleanly.
 My thoughts on your best options are:

1) Tell Orion that the entity beans do not have exclusive write-access to
the database by setting exclusive-write-access="false" in the
orion-ejb-jar.xml (which is orion-specific).  I believe this causes the
data to be re-read at the start of every transaction.

2) Re-write your session bean to makes its database changes through the
entity beans rather than through direct JDBC.

Nick

At 12:02 PM 10/12/00 +0100, you wrote:
Hi gurus

How do I do this cleanly.

I have and Entity that has attributes A,B,C and D. These attributes are all
read from database tables.

A and B are read from Table 1
C and D are read from Table 2

So I have Entity Bean 1, this is loaded by the app server (perhaps by a
findByPrimaryKey) method. This means that Entity Bean 1 is now a cache of
the data in A,B,C and D. 

However while this entity bean is in the cache, via a session bean I change
the data of C and D in table 2. This mean that Entity Bean 1 now has dirty
data. So the question is how do I force the Entity beans to do and EJB
Load.


Also the data in C and D in table 2 may be shared by N number of entity
beans so I may need to refresh N number of Entity Beans depending on which
ones are in the cache.

I only want to call EJB load for Entity beans currently in the cache and of
these I only want to call ejb load for the ones that refer to the changed
data.

Cheers Peter






RE: Invalidating an Entity bean

2000-10-12 Thread Lawrence Fry

Have you tried putting a "required" in the transaction for the entity bean?
Also, if the session bean is not using the entity bean to make the change in
the table, you can't use any of the j2ee transaction stuff. I would only
change the table 2 through the entity bean. You can do that in the session
bean by calling the home, and findby to grab your entity bean, then make the
change to table 2. This way you always have the bean fresh.

If you are worried about having lots of beans lying around, you can make
sure that you only have one instance of your entity bean in your session
bean. The petstore example in the j2ee blueprint uses this approach.

Regards,

Lawrence


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Peter
Delahunty
Sent: Thursday, October 12, 2000 4:02 AM
To: Orion-Interest
Subject: Invalidating an Entity bean


Hi gurus

How do I do this cleanly.

I have and Entity that has attributes A,B,C and D. These attributes are all
read from database tables.

A and B are read from Table 1
C and D are read from Table 2

So I have Entity Bean 1, this is loaded by the app server (perhaps by a
findByPrimaryKey) method. This means that Entity Bean 1 is now a cache of
the data in A,B,C and D.

However while this entity bean is in the cache, via a session bean I change
the data of C and D in table 2. This mean that Entity Bean 1 now has dirty
data. So the question is how do I force the Entity beans to do and EJB Load.


Also the data in C and D in table 2 may be shared by N number of entity
beans so I may need to refresh N number of Entity Beans depending on which
ones are in the cache.

I only want to call EJB load for Entity beans currently in the cache and of
these I only want to call ejb load for the ones that refer to the changed
data.

Cheers Peter