In one example above, the attributes of the entity bean correspond to the columns in the data table, all of which use the default setting. With Column, you can specify the column name in the data table for the property. The declaration of Column is as follows:
@Target ({TYPE, METHOD, FIELD}) @Retention (RUNTIME) public @interface Column {String name () default ""; boolean primaryKey () default false; boolean unique () default false; boolean nullable () default true; boolean insertable () default true; boolean updatable () default true; String columnDefinition () default ""; String secondaryTable () default ""; int length () default 255; int precision () default 0; int scale () default 0 Boolean Specified () default true; // for internal use only} EntityManager is a secondary class for processing entity beans. It can be used to generate / delete persistent entity beans, find entity beans through the primary key, query entity beans by querying language. Below is the declaration of the EntityManager interface:
Package javax.ejb; import java.sql.connection; / *** Interface for interacting and persistence context * / public interface EntityManager {/ ** * Make entity beans from persistent management * @Param entity * / public void Create (Object Entity); / ** * Combine the status and persistence context of a given entity bean. A updated operation similar to the database. * @Param Entity * @return is a combined entity instance * / public
· JNDI.Properties: JNDI property file provides basic configuration properties for accessing JDNI. · Build.xml: Ant profile, to compile, release, test, and clear EJB. Here is a description of the content of each file. Student.javapackage com.kuaff.ejb3.entity; import javax.ejb.CascadeType; import javax.ejb.Entity; import javax.ejb.FetchType; import javax.ejb.GeneratorType; import javax.ejb.Id; import javax.ejb .JoinColumn; import javax.ejb.OneToMany; import javax.ejb.Table; import java.util.ArrayList; import java.util.Collection; import java.io.Serializable; @ Entity @ Table (name = "STUDENT") public Class Student Implements Serializable {// Motor Key Private INT ID; // Student Name Private String Name; // Student Score Private Collection
package com.kuaff.ejb3.entity; import java.io.Serializable; import javax.ejb.Entity; import javax.ejb.GeneratorType; import javax.ejb.Id; import javax.ejb.JoinColumn; import javax.ejb.ManyToOne ; import javax.ejb.Table; @ Entity @ Table (name = "Score") public class Score implements Serializable {private int id; private String name; private int number; private Student student; // primary key automatically generated @Id (generate = GeneratorType.Auto) Public int getId () {return;} public void setId;} public string getname () {return name;} public void setname (String name) {this. name = name;} public int getNumber () {return number;} public void setNumber (int number) {this.number = number;} @ManyToOne @JoinColumn (name = "student_id") public Student getStudent () {return student; } Public void setstudent (student student) {this.student = student;}} This entity bean stores students' scores. Teacher.javapackage com.kuaff.ejb3.entity; import javax.ejb.Remote; import javax.ejb.Remove; import java.util.Map; @Remotepublic interface Teacher {public void addScore (String studentName, Map
package com.kuaff.ejb3.entity; import javax.ejb.EntityManager; import javax.ejb.Inject; import javax.ejb.Remove; import javax.ejb.Stateful; import java.util.Map; import java.util.Set ; @Statefulpublic class TeacherBean implements Teacher {@Inject private EntityManager manager; private Student student; public Student getStudent () {return student;} public void addScore (String studentName, Map