Skip to content

Instantly share code, notes, and snippets.

@wmuron
Created October 20, 2016 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wmuron/f1dc0eae825c45014cb05c17199c03d4 to your computer and use it in GitHub Desktop.
Save wmuron/f1dc0eae825c45014cb05c17199c03d4 to your computer and use it in GitHub Desktop.
Configuration configuration = new Configuration().configure();
SessionFactory factory = configuration.buildSessionFactory();
Session session = factory.getCurrentSession();
Transaction transaction = session.getTransaction();
transaction.begin();
//insert one user
String sql = "INSERT INTO users (id, name, created_at_utc)"
+ "VALUES (1, 'Adam Spring', '2016-06-12 14:54:15')";
Query query = session.createSQLQuery(sql);
query.executeUpdate();
//read one user
User user = (User) session.createCriteria(User.class).list().get(0);
System.out.print("Time in ms: " + user.getCreatedAtUtc().getTime()); //date represented in miliseconds since epoch unix time
transaction.rollback();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment