Created
January 4, 2013 22:50
-
-
Save natbusa/4458202 to your computer and use it in GitHub Desktop.
wrapping up scala and hibernate. Main method/object
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
package com.natalinobusa.jpa | |
import javax.persistence.EntityManager | |
import javax.persistence.EntityManagerFactory | |
import javax.persistence.Persistence | |
import scala.collection.JavaConversions._ | |
object HibernateJpaScalaTutorial { | |
var entityManagerFactory: EntityManagerFactory = Persistence.createEntityManagerFactory( "com.natalinobusa.jpa.HibernateJpaScalaTutorial" ) | |
var entityManager: EntityManager = entityManagerFactory.createEntityManager() | |
def main( args : Array[String]) { | |
entityManager.getTransaction().begin() | |
entityManager.persist( new Buddy( "Natalino", "Busa" ) ) | |
entityManager.persist( new Buddy( "Angelina", "Jolie" ) ) | |
entityManager.persist( new Buddy( "Kate", "Moss" ) ) | |
entityManager.getTransaction().commit() | |
entityManager.getTransaction().begin(); | |
val allBuddies = entityManager.createQuery("From Buddy", classOf[Buddy]).getResultList.toList | |
entityManager.getTransaction().commit(); | |
allBuddies foreach println | |
entityManager.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment