Created
March 14, 2018 01:48
-
-
Save BrentonPoke/a2dd4e242b5026b978da52ee45aa3fd4 to your computer and use it in GitHub Desktop.
Example Animal insertion Main class
This file contains hidden or 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
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment