Originally posted by Purav Shah:
If my table is not normalized, like it is not having any primary key or foriegn key. How can i mention in the entity bean
Keep in mind that what your DB thinks is the primary key for the table doesn't have to be in line with what your container thinks is the primary key. As well, even if you don't have a primary key declared for your table, there probably is a logical primary key.
For example, take the following table that details showtimes for movies
create table movie_times (
title varchar2(100) not null,
venue varchar2(100) not null,
showtime date not null,
num_seats number not null
)
First, note that it's just data (no surrogate keys) being used. One of the main reasons for using surrogate keys is that when one of the venues changes its name, all associated tables must be updated. By giving each row a single-column key -- e.g. id number(10) not null -- you are free to change data attributes without worrying about relations. But anyway, ...
So there's no primary key declared on the table, yet if you look at it, clearly the first three columns uniquely identify a row in the table, and that is precisely the definition of a primary key. So in your bean you need to create a primary key class consisting of those three columns. At this point you'll notice another feature of a surrogate key: multi-column primary key classes for entity beans are a major pain in the ass. By using a single column, you just tell the container the name of the attribute in your bean to be used as the PK.
You'll need to search for examples of creating a PK-class and using it in your beans and client apps. If you have control of the DB schema, I highly recommend adding surrogate keys.
I hope that helped.