Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB & Container Model Questions

 
Harry Tan
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I need your help with questions related to "EJB & Container Model":

Q1)can create() method in Home Interface of an Entity Bean without any parameter?
E.B create() method always create a row in the database. So when there is no information parameter in create() method, where the data comes from?

Q2) is the Unknown-PrimaryKey only CMP feature?
And when it is chosen at runtime would that mean, it must also be specified in a D.D. before the bean is deployed?

Q3)A Session bean called SomeBean has a method called someMethod(), which calls someOtherMethod (same bean) followed by someOtherBeanMethod() of SomeOtherBean. SomeOtherBean is an EntityBean with CMT.
Which is the following is true?

A.SomeOtherBean has no control on the transaction since it is a CMT bean.
B.SomeOtherBean has full access to the UserTransaction object through which it can control transaction
C.SomeOtherBean has access only to the transaction methods in EJBContext, which gives it the poewr to veto transaction.
D.SomeOtherBean has access on the transaction only if the method had RequiresNew set as its transaction attribute.

thanks.
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
alchemist

Welcome to JavaRanch.

Unfortunately your name doesn't gel well with our naming policy. Please take a quick look at the rules and edit your profile accordingly.

Thank you!
 
Sanjay Lalwani
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by alchemist:
Hi,

I need your help with questions related to "EJB & Container Model":

Q1)can create() method in Home Interface of an Entity Bean without any parameter?
E.B create() method always create a row in the database. So when there is no information parameter in create() method, where the data comes from?

ANS: it is not mentioned in the spec. but looks like you can call if your table structure supports.

Q2) is the Unknown-PrimaryKey only CMP feature?
And when it is chosen at runtime would that mean, it must also be specified in a D.D. before the bean is deployed?

ANS: yes it is CMP feature.You will have to define it as Object in your D.D

Q3)A Session bean called SomeBean has a method called someMethod(), which calls someOtherMethod (same bean) followed by someOtherBeanMethod() of SomeOtherBean. SomeOtherBean is an EntityBean with CMT.
Which is the following is true?

A.SomeOtherBean has no control on the transaction since it is a CMT bean.
B.SomeOtherBean has full access to the UserTransaction object through which it can control transaction
C.SomeOtherBean has access only to the transaction methods in EJBContext, which gives it the poewr to veto transaction.
D.SomeOtherBean has access on the transaction only if the method had RequiresNew set as its transaction attribute.

ANS: most appropriate is C.

thanks.
 
Harry Tan
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your reply.

regarding Q1, how would my table structure support empty create() in EntityBean?
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harry,

I found a related thread about Q1.

I am having an CMP entity bean(Item) which contains the field itemID
and is a primary key. I want to make this itemID field as auto increment. How can I do this? What are the steps to take?

I am using JBoss 3.0.0 and not sure if this will work with 2.4.4.
What I do is this :

- I have a create method without parameters
- All my autoincrement primary keys are Integers
- On the create method I call a singleton with the entity name as parameter. It will generate the next key to the entity.
- Then I call the setXXX method to set the primary key.

public abstract class DisciplinaBean implements EntityBean {

...
public DisciplinaPK ejbCreate () throws CreateException,RemoteException {
Integer codigo = new Integer(KeyGen.getKey("Disciplina"));
setCodDisciplina(codigo);
return new DisciplinaPK(codigo);
}
...
}



Hope it helps,
Dan
 
Harry Tan
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dan,

thanks you.
I've just returned from the exam and scored 91% from Exam1.
I've spent the last 2 weeks preparing the exam and the last 2 days reading till midnight.
Very tiring and sleepy now... but really happy...
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harry,

Beautiful score!!!

-- Dan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic