Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package edu.tdt.persistence;
- import java.io.Serializable;
- import java.util.Collection;
- import javax.persistence.Basic;
- import javax.persistence.CascadeType;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.Id;
- import javax.persistence.NamedQueries;
- import javax.persistence.NamedQuery;
- import javax.persistence.OneToMany;
- import javax.persistence.Table;
- import javax.validation.constraints.NotNull;
- import javax.validation.constraints.Size;
- import javax.xml.bind.annotation.XmlRootElement;
- import javax.xml.bind.annotation.XmlTransient;
- /**
- *
- * @author MSI
- */
- @Entity
- @Table(name = "Student", catalog = "ITCenterManagement", schema = "public")
- @XmlRootElement
- @NamedQueries({
- @NamedQuery(name = "Student.findAll", query = "SELECT s FROM Student s")
- , @NamedQuery(name = "Student.findByStudentID", query = "SELECT s FROM Student s WHERE s.studentID = :studentID")
- , @NamedQuery(name = "Student.findByName", query = "SELECT s FROM Student s WHERE s.name = :name")
- , @NamedQuery(name = "Student.findByBirthDay", query = "SELECT s FROM Student s WHERE s.birthDay = :birthDay")
- , @NamedQuery(name = "Student.findByAddress", query = "SELECT s FROM Student s WHERE s.address = :address")
- , @NamedQuery(name = "Student.findByPhoneNumber", query = "SELECT s FROM Student s WHERE s.phoneNumber = :phoneNumber")
- , @NamedQuery(name = "Student.findByEmail", query = "SELECT s FROM Student s WHERE s.email = :email")
- , @NamedQuery(name = "Student.findByA", query = "SELECT s FROM Student s WHERE s.a = :a")})
- public class Student implements Serializable {
- @Size(max = 2147483647)
- @Column(name = "Birthday", length = 2147483647)
- private String birthday;
- @Size(max = 2147483647)
- @Column(name = "PhoneNumber", length = 2147483647)
- private String phoneNumber;
- private static final long serialVersionUID = 1L;
- @Id
- @Basic(optional = false)
- @NotNull
- @Column(name = "StudentID", nullable = false)
- private Long studentID;
- @Size(max = 2147483647)
- @Column(name = "Name", length = 2147483647)
- private String name;
- @Size(max = 2147483647)
- @Column(name = "BirthDay", length = 2147483647)
- private String birthDay;
- @Size(max = 2147483647)
- @Column(name = "Address", length = 2147483647)
- private String address;
- // @Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="Invalid email")//if the field contains email address consider using this annotation to enforce field validation
- @Size(max = 2147483647)
- @Column(name = "Email", length = 2147483647)
- private String email;
- @Size(max = 2147483647)
- @Column(name = "", length = 2147483647)
- private String a;
- @OneToMany(cascade = CascadeType.ALL, mappedBy = "student")
- private Collection<Attendance> attendanceCollection;
- @OneToMany(mappedBy = "studentID")
- private Collection<RegisterInformation> registerInformationCollection;
- @OneToMany(cascade = CascadeType.ALL, mappedBy = "student")
- private Collection<TestResult> testResultCollection;
- public Student() {
- }
- public Student(long studentID) {
- this.studentID = studentID;
- }
- public Student(long studentID, String name, String birthday, String address, String phonenumber, String email) {
- this.studentID = studentID;
- this.name = name;
- this.birthDay = birthday;
- this.address = address;
- this.phoneNumber = phonenumber;
- this.email = email;
- }
- public Long getStudentID() {
- return studentID;
- }
- public void setStudentID(Long studentID) {
- this.studentID = studentID;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getBirthDay() {
- return birthDay;
- }
- public void setBirthDay(String birthDay) {
- this.birthDay = birthDay;
- }
- public String getAddress() {
- return address;
- }
- public void setAddress(String address) {
- this.address = address;
- }
- public String getEmail() {
- return email;
- }
- public void setEmail(String email) {
- this.email = email;
- }
- public String getA() {
- return a;
- }
- public void setA(String a) {
- this.a = a;
- }
- @XmlTransient
- public Collection<Attendance> getAttendanceCollection() {
- return attendanceCollection;
- }
- public void setAttendanceCollection(Collection<Attendance> attendanceCollection) {
- this.attendanceCollection = attendanceCollection;
- }
- @XmlTransient
- public Collection<RegisterInformation> getRegisterInformationCollection() {
- return registerInformationCollection;
- }
- public void setRegisterInformationCollection(Collection<RegisterInformation> registerInformationCollection) {
- this.registerInformationCollection = registerInformationCollection;
- }
- @XmlTransient
- public Collection<TestResult> getTestResultCollection() {
- return testResultCollection;
- }
- public void setTestResultCollection(Collection<TestResult> testResultCollection) {
- this.testResultCollection = testResultCollection;
- }
- @Override
- public int hashCode() {
- int hash = 0;
- hash += (studentID != null ? studentID.hashCode() : 0);
- return hash;
- }
- @Override
- public boolean equals(Object object) {
- // TODO: Warning - this method won't work in the case the id fields are not set
- if (!(object instanceof Student)) {
- return false;
- }
- Student other = (Student) object;
- if ((this.studentID == null && other.studentID != null) || (this.studentID != null && !this.studentID.equals(other.studentID))) {
- return false;
- }
- return true;
- }
- @Override
- public String toString() {
- return "edu.tdt.persistence.Student[ studentID=" + studentID + " ]";
- }
- public String getBirthday() {
- return birthday;
- }
- public void setBirthday(String birthday) {
- this.birthday = birthday;
- }
- public String getPhoneNumber() {
- return phoneNumber;
- }
- public void setPhoneNumber(String phoneNumber) {
- this.phoneNumber = phoneNumber;
- }
- }
- /*
- package edu.tdt.persistence;
- import java.util.List;
- import javax.ejb.Remote;
- /**
- *
- * @author MSI
- */
- @Remote
- public interface ITCenterManagementPersistenceBeanRemote {
- public void insertStudent(Student s);
- //void addResultPK(long classID, long stID);
- public List<Student> getStudent();
- }
- package edu.tdt.persistence;
- import java.math.BigInteger;
- import java.util.Date;
- import java.util.List;
- import javax.ejb.Stateful;
- import javax.ejb.Stateless;
- import javax.persistence.EntityManager;
- import javax.persistence.PersistenceContext;
- /**
- *
- * @author MSI
- */
- @Stateful
- public class ITCenterManagementPersistenceBean implements ITCenterManagementPersistenceBeanRemote {
- @PersistenceContext(unitName = "QuanLiTTTinHocPU")
- private EntityManager entityManager;
- public ITCenterManagementPersistenceBean() {
- }
- @Override
- public void insertStudent(Student s) {
- //Student s = new Student(id, name, birthday, address, phonenumber, email);
- entityManager.persist(s);
- }
- @Override
- public List<Student> getStudent() {
- return entityManager.createNamedQuery("Student.findAll").getResultList();
- }}
- package edu.tdt.test;
- import edu.tdt.persistence.*;
- import edu.tdt.persistence.ClassShift;
- import edu.tdt.persistence.ITCenterManagementPersistenceBean;
- import edu.tdt.persistence.ITCenterManagementPersistenceBeanRemote;
- import edu.tdt.persistence.Staff;
- import edu.tdt.persistence.Student;
- import edu.tdt.persistence.Subject;
- import edu.tdt.persistence.Teacher;
- import edu.tdt.persistence.Class;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.math.BigInteger;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.List;
- import java.util.Properties;
- import java.util.Scanner;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.naming.InitialContext;
- import javax.naming.*;
- import javax.persistence.*;
- import javax.persistence.PersistenceException;
- /**
- *
- * @author MSI
- */
- public class ITCenterManagementTester {
- private Properties props;
- private InitialContext ctx;
- public ITCenterManagementTester() {
- readJNDI();
- }
- private void readJNDI() {
- props = new Properties();
- try {
- props.load(new FileInputStream("jndi.properties"));
- } catch (IOException e) {
- e.getMessage();
- }
- try {
- ctx = new InitialContext(props);
- } catch (NamingException ex) {
- ex.getMessage();
- }
- }
- private String getJNDI() {
- String appName = "";
- String moduleName = "QuanLiTTTinHoc";
- String distinctName = "";
- String sessionBeanName = ITCenterManagementPersistenceBean.class.getSimpleName();
- String viewClassName = ITCenterManagementPersistenceBeanRemote.class.getName() + "?stateful";
- return "ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + sessionBeanName + "!" + viewClassName;
- }
- private void showGUI() {
- System.out.println("n===============================");
- System.out.println("Welcome to IT center Management");
- System.out.println("===============================");
- System.out.print("Options: n1. student n2. List All student n3. Teacher n4. List all Tacher"
- + "n5. Staff n6. List all Staff n7. Add class n8. List of classn9. Add Subject"
- + "n10. Add Class Shift n11. Class Shift list n12. Add Prerequisite Subject n13. Add Schedule n14. Add Exam Schedule"
- + "n15. Add Result n16. Addtendance n17. Teaching Schedule n18. Add Register Information"
- + "n19. List of Register Informationn20. Exit nEnter Choice: ");
- }
- public void testStatefullEJB() {
- try {
- // Scanner definition
- Scanner sc = new Scanner(System.in);
- // ITCenterManagementPersistenceBeanRemote
- ITCenterManagementPersistenceBeanRemote session = (ITCenterManagementPersistenceBeanRemote) ctx.lookup(getJNDI());
- int choice = 0;
- long studentID;
- long teacherID;
- long staffID;
- String name, teachername, staffname;
- String birthday, tbirthday, sbirthday;
- String address, teacheraddress, staffaddress;
- String phonenumber, tphonenumber, sphonenumber;
- String email, teacheremail, staffemail;
- Subject subjectName = new Subject();
- long classID;
- String className;
- String beginDay;
- String endDay;
- int stdNumber;
- double fee;
- long shiftID;
- String shiftName;
- String beginTime;
- String endTime;
- double point;
- long PSubjectID;
- boolean absent;
- Date absentDate;
- //Staff staffID;
- long registerID;
- Date registerDate;
- ClassShift ShiftID;
- String testDate;
- String time;
- Integer hour;
- String room;
- do {
- showGUI();
- choice = Integer.parseInt(sc.nextLine());
- switch (choice) {
- case 1:
- System.out.print("insert Student ID: ");
- studentID = Long.parseLong(sc.nextLine());
- System.out.print("insert Student name: ");
- name = sc.nextLine();
- System.out.print("insert Student birthday: ");
- birthday = sc.nextLine();
- System.out.print("insert Student address: ");
- address = sc.nextLine();
- System.out.print("insert Student phone number: ");
- phonenumber = sc.nextLine();
- System.out.print("insert Student email: ");
- email = sc.nextLine();
- //session.insertStudent(name, birthday, address, phonenumber, email);
- Student s = new Student();
- System.out.println("Done!");
- s.setStudentID(studentID);
- s.setName(name);
- s.setBirthday(birthday);
- s.setAddress(address);
- s.setPhoneNumber(phonenumber);
- s.setEmail(email);
- session.insertStudent(s);
- break;
- case 2:
- List<Student> stu = session.getStudent();
- if (stu.isEmpty()) {
- System.out.println("There is no student in list!");
- }
- System.out.println("n=========================");
- System.out.println("Listing Student");
- System.out.println("=========================");
- for (int i = 0; i < stu.size(); i++) {
- System.out.println((i + 1) + "t" + stu.get(i));
- }
- System.out.println();
- break;
- default:
- break;
- } catch (NamingException ex) {
- Logger.getLogger(ITCenterManagementTester.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
- package edu.tdt.test;
- import javax.ejb.EJBException;
- import javax.persistence.*;
- /**
- *
- * @author MSI
- */
- public class QuanLiTTTinHocTester {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- ITCenterManagementTester test = new ITCenterManagementTester();
- test.testStatelessEJB();
- }
- }
- Exception in thread "main" javax.ejb.EJBException: java.lang.ClassNotFoundException: org.hibernate.exception.SQLGrammarException
- at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:238)
- at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:183)
- at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:146)
- at com.sun.proxy.$Proxy2.insertStudent(Unknown Source)
- at edu.tdt.test.ITCenterManagementTester.testStatelessEJB(ITCenterManagementTester.java:169)
- at edu.tdt.test.QuanLiTTTinHocTester.main(QuanLiTTTinHocTester.java:22)
- Caused by: java.lang.ClassNotFoundException: org.hibernate.exception.SQLGrammarException
- at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
- at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
- at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
- at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
- at java.lang.Class.forName0(Native Method)
- at java.lang.Class.forName(Class.java:348)
- at org.jboss.marshalling.AbstractClassResolver.loadClass(AbstractClassResolver.java:131)
- at org.jboss.marshalling.AbstractClassResolver.resolveClass(AbstractClassResolver.java:112)
- at org.jboss.marshalling.river.RiverUnmarshaller.doReadClassDescriptor(RiverUnmarshaller.java:948)
- at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1255)
- at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
- at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:224)
- at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1745)
- at org.jboss.marshalling.river.RiverObjectInputStream.defaultReadObject(RiverObjectInputStream.java:81)
- at java.lang.Throwable.readObject(Throwable.java:914)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
- at java.lang.reflect.Method.invoke(Method.java:498)
- at org.jboss.marshalling.reflect.SerializableClass.callReadObject(SerializableClass.java:307)
- at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1637)
- at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1606)
- at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1606)
- at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1606)
- at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1285)
- at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
- at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:224)
- at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1745)
- at org.jboss.marshalling.river.RiverObjectInputStream.defaultReadObject(RiverObjectInputStream.java:81)
- at java.lang.Throwable.readObject(Throwable.java:914)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
- at java.lang.reflect.Method.invoke(Method.java:498)
- at org.jboss.marshalling.reflect.SerializableClass.callReadObject(SerializableClass.java:307)
- at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1637)
- at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1606)
- at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1606)
- at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1285)
- at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
- at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:224)
- at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1745)
- at org.jboss.marshalling.river.RiverObjectInputStream.defaultReadObject(RiverObjectInputStream.java:81)
- at java.lang.Throwable.readObject(Throwable.java:914)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
- at java.lang.reflect.Method.invoke(Method.java:498)
- at org.jboss.marshalling.reflect.SerializableClass.callReadObject(SerializableClass.java:307)
- at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1637)
- at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1606)
- at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1606)
- at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1606)
- at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1606)
- at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1285)
- at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
- at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)
- at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:41)
- at org.jboss.ejb.client.remoting.InvocationExceptionResponseHandler$MethodInvocationExceptionResultProducer.getResult(InvocationExceptionResponseHandler.java:79)
- at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:276)
- at org.jboss.ejb.client.EJBObjectInterceptor.handleInvocationResult(EJBObjectInterceptor.java:64)
- at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:290)
- at org.jboss.ejb.client.EJBHomeInterceptor.handleInvocationResult(EJBHomeInterceptor.java:88)
- at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:290)
- at org.jboss.ejb.client.TransactionInterceptor.handleInvocationResult(TransactionInterceptor.java:46)
- at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:290)
- at org.jboss.ejb.client.ReceiverInterceptor.handleInvocationResult(ReceiverInterceptor.java:142)
- at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:265)
- at org.jboss.ejb.client.EJBClientInvocationContext.awaitResponse(EJBClientInvocationContext.java:453)
- at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:204)
- ... 5 more
- C:UsersMSIAppDataLocalNetBeansCache8.2executor-snippetsrun.xml:53: Java returned: 1
- BUILD FAILED (total time: 14 seconds)
- jboss.naming.client.ejb.context=true
- java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory
- java.naming.factory.url.pkgs=org.jboss.ejb.client.naming
- java.naming.provider.url=http-remoting://localhost:8080
- java.naming.security.principal=admin
- java.naming.security.credentials=admin123
Add Comment
Please, Sign In to add comment