Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import beans.Animal;
- import beans.Genus;
- import beans.Location;
- import beans.Species;
- import org.hibernate.Session;
- import org.hibernate.SessionFactory;
- import org.hibernate.Transaction;
- import org.hibernate.cfg.Configuration;
- import org.springframework.orm.hibernate5.HibernateTemplate;
- public class Main {
- public static void main(String[] args) {
- Configuration cfg=new Configuration();
- cfg.configure("hibernate.cfg.xml");
- //creating seession factory object
- SessionFactory factory=cfg.buildSessionFactory();
- //creating session object
- Session session=factory.openSession();
- //creating transaction object
- Transaction t=session.beginTransaction();
- HibernateTemplate template = new HibernateTemplate();
- session.persist(new Location("American Trail Entrance",38.930527, -77.049301));
- session.persist(new Genus("Corvus"));
- session.persist(new Species("Corvus Corax"));
- Animal animal = new Animal();
- 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.");
- animal.setName("Iris");
- animal.setSex('F');
- animal.setPersonality("Ambitious, curious, and capricious");
- animal.setWeight(3.6); // All weight will be in pounds (lbs) for now
- animal.setArea(new Location("American Trail Entrance",38.930527, -77.049301));
- animal.setGenus(new Genus("Corvus"));
- animal.setSpecies(new Species("Corvus Corax"));
- session.persist(animal);
- t.commit();
- session.close();
- }
- }
Add Comment
Please, Sign In to add comment