Created
October 20, 2016 13:33
-
-
Save wmuron/f1dc0eae825c45014cb05c17199c03d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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