Skip to content

Instantly share code, notes, and snippets.

@natbusa
Created January 4, 2013 22:50
Show Gist options
  • Save natbusa/4458202 to your computer and use it in GitHub Desktop.
Save natbusa/4458202 to your computer and use it in GitHub Desktop.
wrapping up scala and hibernate. Main method/object
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