Instantly share code, notes, and snippets.

Embed
What would you like to do?
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