Reputation: 8135
I have a stateful session bean and a CMP Entity bean. Does the entity bean represent the table in the database?
Each client will have their own stateful session bean, and each stateful session bean will have its own entity bean?
If I want to connect the stateful session bean to the entity bean, or should I say that I want to create a new entity bean instance for that stateful bean, what should I do?
When I have the entity bean, I can use it to access to the database , right? If I want to write some data in my session bean to the database, what should I do with the entity bean?
Upvotes: 1
Views: 1620
Reputation: 28577
With EJB 3.0, entity beans are merely POJOs (plain old Java objects) with ORM (object-relational mapping) annotations added to them. They are most commonly used top represent objects instantiated by reading from a database, which also need to be written back to the database at some later stage.
To answer part of your question, yes the class of your entity bean would indeed represent a table in a data base. An instance of the entity bean represents a row in that table. The ORM-annotated attributes of the class represent the column headers of that table.
Stateful session beans can be used to store entity beans as part of its state, but not necessarily - any other objects may be stored. It is up to you to select which is appropriate.
Yes, you will be able to write your entity beans to the data base. To accomplish this you will need to set up and configure a persistence layer - you should have already done this when you set up your Java EE server - and you can then use JDBC APIs to persist your entity beans.
You might want to read up on persistence, ORM and JDBC; how they are used in the context of Java EE - and many of your questions will get answered when you do that.
HTH
Upvotes: 3