1)
@PostConstruct
public void initialize( ){ }
@PreDestroyAccess modifier can be public
public void cleanup( ){ }
@PrePassivate
public void cleanup( ){ }
@PostActivate
public void openConnection( ){ }
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
- Enterprise Bean Provider
- Application Assembler
- Deployer
- EJB Server Provider
- EJB Container Provider
- Persistence Provider
- System Administrator
@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