コード例 #1
0
  public static void main(String[] args) {

    User user = new User();
    user.setBirthday(new Date());
    Name n = new Name();
    n.setFirstName("first name");
    n.setLastName("last name");
    user.setName(n);
    // user.setName("name");
    HibernateUtils.add(user);
    query(user.getName().getFirstName());
  }
コード例 #2
0
  static void addUser(User user) {
    Session s = null;
    Transaction tx = null;
    try {
      s = HibernateUtils.getSession();
      Name name = new Name();
      name.setFirstName("first name");
      name.setLastName("last name");

      User u = new User();
      u.setName(name);
      tx = s.beginTransaction();
      s.save(u);
      tx.commit();

    } finally {
      if (s != null) {
        s.close();
      }
    }
  }