Chris,
I dont agree with the fact that you cant create an
EJB with No primary Key..
Please find these, I got these from JGURU.
But I am not sure how to create a bean without a primary key for websphere..
If any one has done it pols let me know
--------------------------------------------------
Entity Beans with no primary keys Is it possible to create an Entity Bean(CMP) based on table that does not have a primary key.
Derived from A question posed by Pankaj Jha
Topics
Java:API:EJB:EntityBean:CMP, Java:API:EJB:EntityBean

rimary Keys
Author Shirish Poddar
Created Jun 3, 2001
Answer
Yes, you can create CMP Entity Beans without primary keys. But you must be aware of the implications:
Duplicate records may be entered in the table
The findByPrimaryKey() method may return varying rows
In essence, CMP was not designed to not have primary keys, although it can work. The development process is the same as when you create CMP which has primary keys.
Is this item helpful? yes no Previous votes Yes: 0 No: 0
Comments and alternative answers
Entity Beans with no primary keys Is it possible to create an Entity Bean(CMP) based on table that does not have a primary key.
Allen Fogleson, Jun 3, 2001 [replies:1]
You can create a custom Primary key class that contains all the columns in the table. (assuming that would be fairly unique) The only hassles there would be in implementing the hashcode method.
Is this item helpful? yes no Previous votes Yes: 0 No: 0
Re: Entity Beans with no primary keys Is it possible to create an Entity Bean(CMP) based on table that does not have a primary key.
xxxxx yyyyy, Feb 14, 2002
I have created an entity bean for a table which does not have a primary key and it does not work. There is nothing stops you creating an entity bean(CMP) for a table which does not have a primary key but the result return by the finder method is wrong. Though the table does not have primary key, the CMP bean randomly picks a column(most likey the first column) out of a table and mkes it a primary key (which is absolutely wrong). Conclusion: A CMP entity bean for a table which does not have a primary key is not going to work. You must have a primary key to work properly.
Is this item helpful? yes no Previous votes Yes: 0 No: 0
No Primary Key Class in Entity Beans
Shirish Poddar, Jun 9, 2001 [replies:1]
Generally we create a separate primary key class in a Enity Bean. We can do without this creation also. What we can do is we have to write in the EJB-Jar.XML the primary key class name as Java predefined class, such as java.lang.string,any wrapper classes. <prim-key-class>java.lang.String</prim-key-class> <primkey-field>accountId</primkey-field> In this case Duplicate recrods will not be allowed.
Is this item helpful? yes no Previous votes Yes: 0 No: 0
Re: No Primary Key Class in Entity Beans
Allen Fogleson, Jun 14, 2001
But in this case you are saying that the acountID is the primary key... So effectively you have made the table have a "primary key". I think in general we have to be aware that although primary keys may not be required, the detriment to not having at least one unique field is that finders may not operate as expected.
Is this item helpful? yes no Previous votes Yes: 0 No: 0
Yes it is possible
prashant jani PREMIUM, Jan 18, 2002 [replies:1]
in the cmp xml file. Do not provide CMp mapping for the primary key.
Thats all
but u will have to create a sequence at the database level for the primary key.
this will avoid duplicate keys problem
------------------------------------------------
Thanks