Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

.a developer must create an ejbHome<method>

Thread view: 
gk - 10 Nov 2006 04:45 GMT
whats the meaning of the follwong ?

"......a developer must create an ejbHome<method>  for every
home<method> in the home interface.
the name must begin with a prefix ejbHome......"

i never seen a home interface have a method  like ejbHomeXXXX() !!

of course, i have see create()  method in  home interface of Session
Bean and create(),  findByPrimaryKey()  method in entity bean's home
interface.

But whats the meaning of the above ?  what purpose i'll  make that kind
of method ?

can you give one example what they are saying ?
Doug Pardee - 10 Nov 2006 22:31 GMT
EJB home methods are like static methods. They're specific to the
particular EJB class, but not to a particular EJB instance. They were
added in EJB 2.0.

Sun describes them this way (sections 9.5.4 and 9.6.4 of the EJB 2.1
spec):
  "Home methods are methods that the Bean Provider supplies for
business logic that is not specific to an entity bean instance."
www.pulpjava.com - 10 Nov 2006 22:41 GMT
I think you're confusing the content in the EJB Bean class, and the
code in the Home interface. It's create in the home, it's ejb... in the
Bean class.

Here's a few tutorials about BMP and EJB development:

http://www.technicalfacilitation.com/examscam/tf/get.php?link=12bmpentityebeans

Cheers!

-Cameron McKenzie

Free Java Certification Mock Exams:  www.scja.com
Free Java and J2EE Tutorials: www.mcnz.com

www.pulpjava.com www.technicalfacilitation.com www.cameronmckenzie.com

package com.examscam.ejb;
/**
* Local Home interface for Enterprise Bean: PersonBMP
*/
public interface PersonBMPLocalHome extends javax.ejb.EJBLocalHome {
/**
* Creates an instance from a key for Entity Bean: PersonBMP
*/
public com.examscam.ejb.PersonBMPLocal create()
throws javax.ejb.CreateException;
/**
* Finds an instance using a key for Entity Bean: PersonBMP
*/
public com.examscam.ejb.PersonBMPLocal findByPrimaryKey(
com.examscam.ejb.PersonBMPKey primaryKey)
throws javax.ejb.FinderException;
}

package com.examscam.ejb;
/**
* Bean implementation class for Enterprise Bean: PersonBMP
*/
public class PersonBMPBean implements javax.ejb.EntityBean {

String name;
int age;

/**
* @return Returns the age.
*/
public int getAge() {
System.out.println("In getAge");
return age;
}
/**
* @param age The age to set.
*/
public void setAge(int age) {
System.out.println("In setAge");
this.age = age;
}
/**
* @return Returns the name.
*/
public String getName() {
System.out.println("In getName");
return name;
}
/**
* @param name The name to set.
*/
public void setName(String name) {
System.out.println("In setName");
this.name = name;
}
private javax.ejb.EntityContext myEntityCtx;
/**
* ejbActivate
*/
public void ejbActivate() {
System.out.println("In ejbActivate");
}
/**
* ejbLoad
*/
public void ejbLoad() {
System.out.println("In ejbLoad");
}
/**
* ejbPassivate
*/
public void ejbPassivate() {
System.out.println("In ejbPassivate");
}
/**
* ejbRemove
*/
public void ejbRemove() throws javax.ejb.RemoveException {
System.out.println("In ejbRemove");
}
/**
* ejbStore
*/
public void ejbStore() {
System.out.println("In ejbStore");
}
/**
* getEntityContext
*/
public javax.ejb.EntityContext getEntityContext() {
System.out.println("In getEntityContext");
return myEntityCtx;
}
/**
* setEntityContext
*/
public void setEntityContext(javax.ejb.EntityContext ctx) {
System.out.println("In setEntityContext");
myEntityCtx = ctx;
}
/**
* unsetEntityContext
*/
public void unsetEntityContext() {
System.out.println("In unsetEntityContext");
myEntityCtx = null;
}
/**
* ejbCreate
*/
public com.examscam.ejb.PersonBMPKey ejbCreate()

throws javax.ejb.CreateException {
System.out.println("In ejbCreate");
return null;
}
/**
* ejbPostCreate
*/
public void ejbPostCreate() throws javax.ejb.CreateException {
System.out.println("In ejbPostCreate");
}
/**
* ejbFindByPrimaryKey
*/
public com.examscam.ejb.PersonBMPKey ejbFindByPrimaryKey(
com.examscam.ejb.PersonBMPKey primaryKey)
throws javax.ejb.FinderException {
System.out.println("In findBy");
return null;
}

> EJB home methods are like static methods. They're specific to the
> particular EJB class, but not to a particular EJB instance. They were
[quoted text clipped - 4 lines]
>    "Home methods are methods that the Bean Provider supplies for
> business logic that is not specific to an entity bean instance."
gk - 10 Nov 2006 22:51 GMT
> EJB home methods are like static methods. They're specific to the
> particular EJB class, but not to a particular EJB instance. They were
[quoted text clipped - 4 lines]
>    "Home methods are methods that the Bean Provider supplies for
> business logic that is not specific to an entity bean instance."

ok...so

is this *home methods*  ONLY for entity beans ?

what kind of code is written in these *home methods* ?

you told , its a  particular to a class .....does it  set any
environment properties etc for the whole class in this method ?

please explain , this part is not clear ....why and how we use it ?
Doug Pardee - 10 Nov 2006 23:25 GMT
> is this *home methods*  ONLY for entity beans ?

Yes. Only for entity beans.

> what kind of code is written in these *home methods* ?

Whatever you need. Any code that you think should be part of that
particular EJB class but is not associated with any specific entity.

> does it  set any environment properties etc for the
> whole class in this method ?

Environment properties? Those come from the deployment descriptor.

> please explain , this part is not clear ....why and how we use it ?

Most people never use it. It wasn't even available prior to EJB 2.0.
It's there for the special cases when you need it.

Here's one obvious example:

Suppose that you have an entity EJB associated with a particular
database table (that's not much of a stretch). Now suppose that you
need a count() method that tells you how many rows there are in that
table. In the old days of EJB 1 you'd have to write a "finder" method
that returned the primary keys for all of the rows, which would then
cause the container to create entity beans for all of the rows, just so
you could count how many EJBs you got back. With EJB 2 and home
business methods, you can just do a "SELECT COUNT(*)" and return the
int value. This is a big improvement when you're dealing with tables
with thousands or millions of rows.
gk - 10 Nov 2006 23:59 GMT
> > is this *home methods*  ONLY for entity beans ?
>
[quoted text clipped - 27 lines]
> int value. This is a big improvement when you're dealing with tables
> with thousands or millions of rows.

nice example.
thank you


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.