/** @param args the command line arguments */
  public static void main(String[] args) {
    Session s = NewHibernateUtil.getSessionFactory().openSession();
    Transaction ts = s.beginTransaction();

    Person p =
        new Person(
            "Patrick",
            "",
            "Kann",
            "8-56",
            "21041989",
            "26092013",
            "",
            "",
            "",
            0,
            0,
            0,
            "",
            0,
            null);
    Guest g = new Guest(p, "Lars", "", "Kann", "21041989", "");
    Set guests = new HashSet();
    guests.add(g);
    p.setGuests(guests);
    s.save(p);
    ts.commit();
  }
Esempio n. 2
0
  public static void main(String[] args) {

    EntityManagerFactory emf =
        Persistence.createEntityManagerFactory(DeploymentConfiguration.PU_NAME);
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();

    try {
      File postfile = new File("city.txt");
      FileReader fileReader = new FileReader(postfile);
      BufferedReader bufferedReader = new BufferedReader(fileReader);
      StringBuffer stringBuffer = new StringBuffer();
      String line = null;
      city = new ArrayList();

      while (true) {
        line = bufferedReader.readLine();

        stringBuffer.append(line);
        stringBuffer.append("\n");
        city.add(line);

        fileReader.close();
      }
    } catch (IOException e) {
    }

    try {
      File cityfile = new File("post.txt");
      FileReader fileReader1 = new FileReader(cityfile);
      BufferedReader bufferedReader1 = new BufferedReader(fileReader1);
      StringBuffer stringBuffer1 = new StringBuffer();
      String line1 = null;
      post = new ArrayList();

      while (true) {
        line1 = bufferedReader1.readLine();

        stringBuffer1.append(line1);
        stringBuffer1.append("\n");
        post.add(line1);

        fileReader1.close();
      }

    } catch (IOException e) {
    }
    try {
      File streetfile = new File("Street.txt");
      FileReader fileReader3 = new FileReader(streetfile);
      BufferedReader bufferedReader3 = new BufferedReader(fileReader3);
      StringBuffer stringBuffer3 = new StringBuffer();
      String line3 = null;
      street = new ArrayList();

      while (true) {

        line3 = bufferedReader3.readLine();

        stringBuffer3.append(line3);
        stringBuffer3.append("\n");
        street.add(line3);

        fileReader3.close();
      }
    } catch (IOException e) {
    }
    try {
      File additionalInfofile = new File("additionalInfo.txt");
      FileReader fileReader3 = new FileReader(additionalInfofile);
      BufferedReader bufferedReader3 = new BufferedReader(fileReader3);
      StringBuffer stringBuffer3 = new StringBuffer();
      String line3 = null;
      additionalInfo = new ArrayList();

      while (true) {

        line3 = bufferedReader3.readLine();

        stringBuffer3.append(line3);
        stringBuffer3.append("\n");
        additionalInfo.add(line3);

        fileReader3.close();
      }
    } catch (IOException e) {
    }

    try {
      File additionalInfofile = new File("phone.txt");
      FileReader fileReader3 = new FileReader(additionalInfofile);
      BufferedReader bufferedReader3 = new BufferedReader(fileReader3);
      StringBuffer stringBuffer3 = new StringBuffer();
      String line3 = null;
      phone = new ArrayList();

      while (true) {

        line3 = bufferedReader3.readLine();

        stringBuffer3.append(line3);
        stringBuffer3.append("\n");
        phone.add(line3);

        fileReader3.close();
      }
    } catch (IOException e) {
    }

    try {
      File additionalInfofile = new File("adphoneinfo.txt");
      FileReader fileReader3 = new FileReader(additionalInfofile);
      BufferedReader bufferedReader3 = new BufferedReader(fileReader3);
      StringBuffer stringBuffer3 = new StringBuffer();
      String line3 = null;
      addphoneinfo = new ArrayList();

      while (true) {

        line3 = bufferedReader3.readLine();

        stringBuffer3.append(line3);
        stringBuffer3.append("\n");
        addphoneinfo.add(line3);

        fileReader3.close();
      }
    } catch (IOException e) {
    }
    try {
      File additionalInfofile = new File("hobby.txt");
      FileReader fileReader3 = new FileReader(additionalInfofile);
      BufferedReader bufferedReader3 = new BufferedReader(fileReader3);
      StringBuffer stringBuffer3 = new StringBuffer();
      String line3 = null;
      hobby = new ArrayList();

      while (true) {

        line3 = bufferedReader3.readLine();

        stringBuffer3.append(line3);
        stringBuffer3.append("\n");
        hobby.add(line3);

        fileReader3.close();
      }
    } catch (IOException e) {
    }
    try {
      File additionalInfofile = new File("hobbydec.txt");
      FileReader fileReader3 = new FileReader(additionalInfofile);
      BufferedReader bufferedReader3 = new BufferedReader(fileReader3);
      StringBuffer stringBuffer3 = new StringBuffer();
      String line3 = null;
      hobbydec = new ArrayList();

      while (true) {

        line3 = bufferedReader3.readLine();

        stringBuffer3.append(line3);
        stringBuffer3.append("\n");
        hobbydec.add(line3);

        fileReader3.close();
      }
    } catch (IOException e) {
    }

    try {
      File personfile = new File("person.txt");
      FileReader fileReader3 = new FileReader(personfile);
      BufferedReader bufferedReader3 = new BufferedReader(fileReader3);
      StringBuffer stringBuffer3 = new StringBuffer();
      String line3 = null;
      person = new ArrayList();

      while (true) {

        line3 = bufferedReader3.readLine();

        stringBuffer3.append(line3);
        stringBuffer3.append("\n");
        person.add(line3);

        fileReader3.close();
      }
    } catch (IOException e) {
    }

    try {
      File efternavnfile = new File("efternavn.txt");
      FileReader fileReader3 = new FileReader(efternavnfile);
      BufferedReader bufferedReader3 = new BufferedReader(fileReader3);
      StringBuffer stringBuffer3 = new StringBuffer();
      String line3 = null;
      efternavn = new ArrayList();

      while (true) {

        line3 = bufferedReader3.readLine();

        stringBuffer3.append(line3);
        stringBuffer3.append("\n");
        efternavn.add(line3);

        fileReader3.close();
      }
    } catch (IOException e) {
    }

    try {
      File efternavnfile = new File("email.txt");
      FileReader fileReader3 = new FileReader(efternavnfile);
      BufferedReader bufferedReader3 = new BufferedReader(fileReader3);
      StringBuffer stringBuffer3 = new StringBuffer();
      String line3 = null;
      email = new ArrayList();

      while (true) {

        line3 = bufferedReader3.readLine();

        stringBuffer3.append(line3);
        stringBuffer3.append("\n");
        email.add(line3);

        fileReader3.close();
      }
    } catch (IOException e) {
    }

    int count = 0;

    for (int i = 0; i < 59; i++) {

      String citynavn = city.get(count);
      String postnummer = post.get(count);

      c = new CityInfo(postnummer, citynavn);

      count++;
      em.persist(c);
      em.flush();
    }

    int count1 = 0;

    for (int i = 0; i < 59; i++) {

      String streetnavn = street.get(count1);
      String additionalInfotal = additionalInfo.get(count1);

      String neupost = post.get(count1);
      Object ms = em.find(CityInfo.class, neupost);

      count1++;

      a = new Address(streetnavn, additionalInfotal, (CityInfo) ms);

      em.persist(a);
      em.flush();
    }

    int count9 = 0;
    for (int i = 0; i < 14; i++) {
      String hoby = hobby.get(count9);
      String hobydec = hobbydec.get(count9);

      hb = new Hobby(hoby, hobydec);

      count9++;

      em.persist(hb);
    }

    int count8 = 0;
    for (int i = 0; i < 59; i++) {

      String personname = person.get(count8);
      String personefternavnl = efternavn.get(count8);
      String nextemeil = email.get(count8);

      String neuper = street.get(count8);
      Object mineadres = em.find(Address.class, neuper);

      h = new Person(personname, personefternavnl, nextemeil, (Address) mineadres);

      h.addHobby(hb);
      count8++;

      em.persist(h);
      em.flush();
    }

    em.persist(c);
    em.getTransaction().commit();
  }