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。