Software:
News ToolsReg Shops |
Migrating EJB 2.1 Entity and Session Beans to EJB 3.0The nuts and boltsPublished Tuesday 25th April 2006 06:02 GMT Table 1. EJB 3.0 Metadata Annotations
The EJB 3.0 annotation types are defined in the Listing 8. CatalogBean.java. EJB 3.0 Entity Bean POJO Class
import javax.persistence.Entity;
import javax.persistence.NamedQuery;
import javax.persistence.Id;
import javax.persistence.Column;
import javax.persistence.OneToMany;
@Entity
@NamedQuery(name="findByJournal",
queryString="SELECT DISTINCT OBJECT(obj) FROM Catalog obj WHERE obj.journal = ?1")
public class CatalogBean{
public CatalogBean() {}
public CatalogBean(String catalogId) {
this.catalogId=catalogId;
}
private String catalogId;
private String journal;
private String publisher;
@Id
@Column(name="CatalogId", primaryKey="true")
public String getCatalogId() {return catalogId;}
public void setCatalogId() {this.catalogId=catalogId;}
public void setJournal(String journal) {this.journal=journal;}
public String getJournal() {return journal;}
public void setPublisher(String publisher) {this.publisher=publisher;}
public String getPublisher() {return publisher;}
private java.util.Collection<Edition> editions;
@OneToMany
public void setEditions(java.util.Collection editions) {
this.editions=editions;
}
public java.util.Collection getEditions() {return editions;}
}
An EJB 2.1 entity bean is created with the
InitialContext ctx=new InitialContext();
Object objref=ctx.lookup("CatalogLocalHome");
CatalogLocalHome catalogLocalHome=(CatalogLocalHome)objref;
//Create an instance of Entity bean
CatalogLocal catalogLocal=(CatalogLocal)catalogLocalHome.create(catalogId);
The example client class for the EJB 2.1 entity bean class is available in the resources zip file . To access the getter/setter methods of an entity bean, the remote/local object in EJB 2.1 is obtained with the finder methods:
CatalogLocal catalogLocal =
(CatalogLocal) catalogLocalHome.findByPrimaryKey(catalogId);
A entity bean instance is removed with the catalogLocal.remove(); The example client class for the EJB 2.1 entity bean class is available in the resources zip file. An EJB 3.0 entity bean class does not include the local/remote and home/local home interfaces. In EJB 3.0, persistence and lookup is provided by the Some of the methods in the
Track this type of story as a custom Atom/RSS feed or by email.
|
Developer HeadlinesThe UK's latest developer news from MSDN |
Top 20 stories • All The Week’s Headlines • Archive • Search