I'm not expert on hibernate, but I'm trying to learn it with Scala. So far I could only find hibernate documentation with Java, but no scala.
My confusion is about when I should use persistence.xml, and when an hibernate.cfg.xml.
I have this doubt because I see examples with both, and my code is sometimes complaining about not finding persistence.xml, and when it finds it then again complains about not finding hibernate properties...so I feel confuse. I feel a kind of friction between Scala/Java or different standards...
Any suggestion?
This is my main app:
package nl.busa.jpa
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
object HibernateJpaScalaTutorial {
var entityManagerFactory: EntityManagerFactory = Persistence.createEntityManagerFactory("nl.busa.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
println(allBuddies);
entityManager.close();
}
}
This is my hibernate.cfg.xml
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE hibernate-configuration SYSTEM
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="hibernate.cfg.xml">
<property name = "hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name = "hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name = "hibernate.connection.url">jdbc:mysql://localhost/test</property>
<property name = "hibernate.connection.username">root</property>
<property name = "hibernate.connection.password"></property>
<property name="hibernate.hbm2ddl.auto">create"</property>
</session-factory>
</hibernate-configuration>
And my error message is this:
Could not find any META-INF/persistence.xml file in the classpath