Guest User

Untitled

a guest
Mar 22nd, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. import beans.Animal;
  2. import beans.Genus;
  3. import beans.Location;
  4. import beans.Species;
  5. import org.hibernate.Session;
  6. import org.hibernate.SessionFactory;
  7. import org.hibernate.Transaction;
  8. import org.hibernate.cfg.Configuration;
  9. import org.springframework.orm.hibernate5.HibernateTemplate;
  10.  
  11. public class Main {
  12. public static void main(String[] args) {
  13.  
  14. Configuration cfg=new Configuration();
  15. cfg.configure("hibernate.cfg.xml");
  16.  
  17. //creating seession factory object
  18. SessionFactory factory=cfg.buildSessionFactory();
  19.  
  20. //creating session object
  21. Session session=factory.openSession();
  22.  
  23. //creating transaction object
  24. Transaction t=session.beginTransaction();
  25.  
  26. HibernateTemplate template = new HibernateTemplate();
  27.  
  28. session.persist(new Location("American Trail Entrance",38.930527, -77.049301));
  29.  
  30. session.persist(new Genus("Corvus"));
  31.  
  32. session.persist(new Species("Corvus Corax"));
  33.  
  34.  
  35. Animal animal = new Animal();
  36. animal.setInfo("The Common Raven is one of the most intelligent species known to humanity.\nIris is fully flighted and was hand-raised to be an education ambassador.");
  37. animal.setName("Iris");
  38. animal.setSex('F');
  39. animal.setPersonality("Ambitious, curious, and capricious");
  40. animal.setWeight(3.6); // All weight will be in pounds (lbs) for now
  41. animal.setArea(new Location("American Trail Entrance",38.930527, -77.049301));
  42. animal.setGenus(new Genus("Corvus"));
  43. animal.setSpecies(new Species("Corvus Corax"));
  44. session.persist(animal);
  45. t.commit();
  46. session.close();
  47. }
  48. }
Add Comment
Please, Sign In to add comment