Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!

Safin Ahmed

+ Follow
since Feb 08, 2006
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Safin Ahmed

I'm using Sun Application Server 8, where i'm deploying some CMPs
I was wondering how can i Invalidate the Cache SAS8 makes for each of my CMPs

In Caucho i can do this

In WebLogic i have
public void invalidate(Object pk) throws RemoteException;
public void invalidate (Collection pks) throws RemoteException;
public void invalidateAll() throws RemoteException;

How can i do it in SAS8 ?

So i found out the real problem
And the problem is that my CustomerHistory has a Text Field, as in a MS SQL Server TEXT Field
When i changed it to a VARCHAR, it started working
The strangest thing is that Customer also has a TEXT Field (mapped to a String) and i can do Finds without any problems

So my question now is how can i work with TEXT in CMPs ?


I'm with a strange problem, that i can't find a solution for, even though it sound like a pretty standard thing

I have a CMP that has a CMR (1:N) with another CMP
Let's say that a Customer has a CMR with CustomerHistory (that is, a Customer has many CustomerHistory items)
Customer has a simple PK (a Long Type ID)
CustomerHistory has a composed PK (a Long Type CustomerID and a Long Type Version)

Well in here lies the problem, because in CustomerHistory, CustomerID is part of the Primary Key, and also is the Foreign Key to Customer

Because of that (or at least i think it's because of that)
When i'm in a CustomerBean and i try to get All the CustomerHistoryBean that are associated with this Customer i get a Collection of NULLs
What is more strange is that i get a correct number of NULL objects, that is, if in a Customer i have 5 CustomerHistorys related, i get a Collection with 5 NULLs

Anyone knows how can i solve this ?

In my Database i have other tables with other relations, and all of them work fine because all of them have simple PKs, except for this one, which is the one that doesn't work

Any help would be appreciated

Thanks in advanced
Dilip thanks for your reply, it works
What strikes me as odd is that they used List.subList in such an important Book (Core J2EE Patterns)
Then why doesn't it work for me ?

They use a POJO instead of a SessionBean, but nonetheless, if it was a problem , i think someone would have noticed it by now
Thanks for the reply

If i use a Collection it works fine (but i have to code the subList method by myself) i wanted to use the List so i could use their subList function

It's strange because in the Core J2EE patterns book they use a List with a call to subList, but they use a POJO instead of a SessionBean, so i don't know if i should be using List in a EJB also
I'm trying to implement a Value List Handler
And I have this method on the Session Bean

public List getElements(int start, int end) throws CustomerException {
return customerList.subList(start,end);

Where customerList is of List type

When i try to call this method i get the following error
Caused by: java.lang.ClassCastException: java.util.RandomAccessSubList

Any ideas?
First of all thanks for the reply

I've figured out that the problem is because I have a Customer with a Collection of CustomerHistory

and CustomerHistory has a compound Primary Key (id and version), and the ID is the foreign key to the Customer
That's why everything comes nulled, i've tried with other 1-N relations, and all of them worked (because all of them have simple keys)

i'm using Sun Studio Enterprise 8
And i've used it to create two CMPs from Database
They have a relationship 1-N, that is, one Customer has N CustomerHistory

In the Customer CMP everything is OK
In the CustomerHistory CMP when i do a findBy(any field) i get a Collection with nulls
the number of elements in the Collection is correct but every element is a null
What can be happening here?

The IDE generated everything for me, so i think the configuration files are pretty much OK
The CustomerHistory table has a Primary Key with 2 fields, i don't know if that can be a problem, but i don't think so

Any ideas ?


i have a CMP with a Collection of other CMPs (that is, i have a CMR between two CMPs)

Let's say that the CMP Invoice, has a Collection of Line CMPs

How can i add one Line the a given Invoice ?

I've been looking at the CMP and my only option is to get the entire collection, add the Line and then set the collection to the CMP, but i really don't think this is the way to go

Any ideas ?

Thank you
Hi, thanks again for your response,

for me the big issue here is that i have 2 separate problems, and either of them could require VC. But i don't want to have 2 version columns
I can't use the same column for both problems, because one is invisible to me, the Server does all the work, and doesn't allow me to poke around there.

Problem no1. I have the information i send to the CMP, when the CMP goes to store the data into the database he can be doing so from an old record (the web UI example). And i need to avoid this kind of errors.

First solution (i'm using) - Nefore he stores he has to check the version, to see if this is the correct version. If it is, then he can go ahead and store the thing.
This version column is managed by the server, i can touch it.

Now i have a second problem. The user has a DTO (or TO or Value Object) with the information matching the CMP, layed out on a nice web page. 5mts later (can be enough for someone else to make a change) he goes and send this to the SessionFacade.
And in here lies the problem, the SessionFacade has to findByPrimary key the CMP, and doing so he will get the brand new one in the DB.
So when he commit this information back to the CMP (that will search for problem no.1) everything will work fine.

The obvious solution, is a version checking, when the sessionFacade findByPrimaryKey the CMP, he could check the version in the CMP and the version in the DTO and if they were diferent then it's Exception time.
But as i said i don't have access to the version from problem 1

So i need one version for problem 1 and another for problem 2, and this doesn't strike me as the right solution

I think what you said "The read-write version causes notification events to be sent to the cache; the primary keys are part of that notification"
Can help me in problem 2, because instead of going to the database i can just the the CMP from the cache

About "You could do something as simple as a timeout on requests", it's hard, because data can be changed every second, or every hour, there would not be a right time for timeouts

For "...which means you could already be in a position to compare the current entity bean state to what was last shown to the user, and apply business logic to decide when they differ too much to allow the commit."
I think that problem 2 doesn't allow this solution, because the logic would have to be in a kind of Version Column, and in there lies the problem

Thank you for your help

If you could nudge me in the right direction i would appreciate it. I think
the problem is much clearer now

(Sorry for any english mistakes)
Thank you for your reply
I didn't read it the first time you replied, so thanks for replying again

I'll give you an overview of my problem

I have a database with clients (and other entities, but let's focus on this one, the other will have the same problem/solution)

I want users to be able to read clients very often, and to update them only once in a while

To do this, i want the information to be cached, so that when someone wants to read a client he can read it without going to the database.

But imagine i'm watching this client, and this has been siting in my screen for a couple of hours, meanwhile, in another computer someone who had the same client, has updated a field. Now when i want to update my client with the information i've put in, this should give me an error, because i was updating a stale version

How can i solve this without using VC ?


i'm trying to use this Versioning EJB so that i can use the caching in a Optimistic fashion

But i have some questions

I have a SessionFacade followed by and CMP kind of architecture

Imagine a client ask for a CMP to the SessionBean, i return a DTO with this information. Then the client wants to do an Update, he sends it to the SessionBean, that will look for the CMP (doing a findByPrimaryKey) at this time, all my information could have been compromised, because the information i got from the Database and the information i have on the DTO is potentially different.

Using version consistency i cant access the Version Column, so i can't verify if the version is correct when the SessionBean get the CMP (to do the update)

Version consistency will be good for me because i'm in a clustered enviornment, so i know that if someone in the other server changed something in the Database, the CMP will not allow me to update the info using and old bean.
So i need this Version Consistency

I'm faced with an option of having Version Consistency for Clustered Enviornment, and a second version column so that i can check consistency in the call between client and CMP

But this doesn't make any sense

Any thoughts?


i've been reading about Version Consistency in EJB
And i'm having difficulties understanding something

The ejbStore() method validates the correct version in the Bean in the dataase, and update call adds 1 to the row when it enters the database (by the means of a trigger).
So far so good.

How does this information get mapped again in the EJB ? How does the bean get the new version value ?
Do we have to find the bean again as a new bean?

Because i read that
"...except that the ejbLoad() method loads its initial data (including the version number) from an internal cache."

Meaning that we will load always the same bean if we don't create a new one.
And if we save it once, we will never be able to save it again, because we will have a incorrect version number

Can someone explain this to me ?

So, i found the problem
I had the SessionBean configured as a Stateful Session Bean
But if i change it to Stateless it starts working
I still didn't figured out why (as no Load, Store, Passivation or Activation code exists to keep or get the Hashtable)

So if any one could explain it to me, it would be nice