.a developer must create an ejbHome<method>

G

gk

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 ?
 
D

Doug Pardee

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."
 
W

www.pulpjava.com

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;
}
 
G

gk

Doug said:
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."

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 ?
 
D

Doug Pardee

gk said:
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.
 
G

gk

Doug said:
Yes. Only for entity beans.


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


Environment properties? Those come from the deployment descriptor.


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.


nice example.
thank you
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top