File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes how to create a new entity bean without insert new records Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "how to create a new entity bean without insert new records" Watch "how to create a new entity bean without insert new records" New topic
Author

how to create a new entity bean without insert new records

Mike Lin
Ranch Hand

Joined: Oct 29, 2002
Posts: 48
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


SCJP1.4 <br />Best wishes!<br />中国人!
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Then we use the findBy***() methods.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Mike Lin
Ranch Hand

Joined: Oct 29, 2002
Posts: 48
Can findByPrimaryKey() CREATE a new Entity Bean??? if we have none Entity Beans at first?
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1064
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

Joined: Oct 29, 2002
Posts: 48
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

Joined: Mar 06, 2001
Posts: 1209
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

Joined: Aug 27, 2003
Posts: 1064
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...
 
 
subject: how to create a new entity bean without insert new records