SCBCD 5 Short Notes

My SCBCD 5 Short Notes..

1)
@PostConstruct
public void initialize( ){ }
@PreDestroy
public void cleanup( ){ }


@PrePassivate
public void cleanup( ){ }

@PostActivate
public void openConnection( ){ }
Access modifier can be  public
                                     protected
                                     default
                                     private
Not static
Not Final
Not throw checked Exceptions
 
@Remove
public void cancel( ){ }

@PostConstruct, @PreDestroy can be used with stateful, stateless session beans
@PrePassivate, @PostActivate, @Remove used with stateful session beans

 2)
Transaction attributes
Reference : EJB 3 in Action
Transaction Attribute Caller Transaction Exists? Effect
REQUIRED No Container creates a new transaction.
Yes Method joins the caller’s transaction.
REQUIRES_NEW No Container creates a new transaction.
Yes Container creates a new transaction and the caller’s transaction is suspended
SUPPORTS No No transaction is used.
Yes Method joins the caller’s transaction.
MANDATORY No javax.ejb.EJBTransactionRequired-Exception is thrown.
Yes Method joins the caller’s transaction.
NOT_SUPPORTED No No transaction is used.
Yes The caller’s transaction is suspended and the method is called without a transaction
NEVER No No transaction is used.
Yes javax.ejb.EJBException is thrown


3)

@Entity
public class Project{
    @ManyToMany(mappedBy="projects")
    Set<Employee> emps;
}

@Entity
public class Employee{
    @ManyToMany(targetEntity=Project.class)
    Collection projects;
}
If we not use Generics we have to use targetEntity


4 )
@MessageDriven
public class MyMessageBean implements MessageListener{
    
    public MyMessageBean(){}
    
    public void onMesage(Message message){
        
    }
}


5) EJB Roles
  1. Enterprise Bean Provider
  2. Application Assembler
  3. Deployer
  4. EJB Server Provider
  5. EJB Container Provider
  6. Persistence Provider
  7. System Administrator
6)
 @PersistenceUnit
EntityManagerFactory emf;

@PersistenceContext
EntityManager em;

7)Defining a Runtime Exception

@ApplicationException
public class MyException extends java.lang.RuntimeException

8)  ejb-jar is a contract between ,

           Bean Provider and Application Assembler
           Application Assembler and Deployer

No comments:

Post a Comment