Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to create a new entity bean without insert new records

 
Mike Lin
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when we call EJBCreate() in CMP,the container will insert a new record into database .yet sometimes we just want to get or view some records ,what we can do ???
thanks a lot
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then we use the findBy***() methods.
 
Mike Lin
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can findByPrimaryKey() CREATE a new Entity Bean??? if we have none Entity Beans at first?
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mike Lin:
Can findByPrimaryKey() CREATE a new Entity Bean??? if we have none Entity Beans at first?

No, findByPrimaryKey() method is supposed to be a read-only method. It is not supposed to create/update the rows in the database. To create() rows in the database, you should use create() methods in the entity bean.
It is also possible not to have create() methods in an entity bean, if your design does not include inserstion of new rows by the entity beans. U can have read-only entity beans with no create() methods...and have only finder methods and some business methods.
But findByPrimaryKey() is a compulsory method, to be defined in ur entity bean.
 
Mike Lin
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what i want is not a read only Entity Bean but a BEAN replasents a record of a DB and maybe i will update it.
so how can i get that Entity Bean?
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Am not clear about the read-only beans that is being discussed here.
But i guess some of the business method might be provided to update the bean. So since the finder returns a valid Local / remote reference, cant i update the bean using that reference? I understand that i cannot create rows in the DB since i have not provided a create.
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mike Lin:
what i want is not a read only Entity Bean but a BEAN replasents a record of a DB and maybe i will update it.
so how can i get that Entity Bean?

-You need to design/write an Entity Bean. If you are not interested in having create() methods to insert new rows in your associated table, then don't have it. You could have finder methods and business methods. You may have to refer an EJB book to know, details of writing an Entity Bean...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic