public class EntityTestBean implements EntityTest { private @Inject EntityManager manager; public void createData() { Teacher teacher1 = new Teacher(); Teacher teacher2 = new Teacher();
Set students1 = new HashSet(); Set students2 = new HashSet(); Student student1 = new Student(); Student student2 = new Student(); Student student3 = new Student();
Dossier dossier1 = new Dossier(); Dossier dossier2 = new Dossier(); Dossier dossier3 = new Dossier(); teacher1.setId(new Long(1)); teacher1.setName("hushisheng"); teacher1.setInfo("胡時勝教授,博士生導師"); manager.create(teacher1); teacher2.setId(new Long(2)); teacher2.setName("liyongchi"); teacher2.setInfo("李永池教授,博士生導師"); manager.create(teacher2);
public class Client { public static void main(String[] args) throws NamingException { InitialContext ctx = new InitialContext(); StudentDAO dao = (StudentDAO) ctx.lookup(StudentDAO.class.getName()); int id = dao.create("晁","岳攀","8","smallnest@kuaff.com","男"); dao.create("朱","立煥","6","zhuzhu@kuaff.com","女"); List list = dao.findAll(); for(Object o:list) { Student s = (Student)o; System.out.printf("%s%s的性別:%s%n",s.getName().getFirst(),s.getName().getLast(),s.getGender()); dao.evict(s); } } }
這個客戶端用來測試。
請運行{$JBOSS_HOME}/bin目錄下的run.bat: run –c all,啟動JBOSS。