0

I am using Play 1.2.5. I am using hibernate in my play project. I have added the database info in application.conf as follows

db.driver=com.mysql.jdbc.Driver
db.url=jdbc:mysql://localhost:3306/dbname
db.user=username
db.pass=password

Also I have added the database info in the hibernate.cfg.xml under the conf folder as follows,

<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/dbname</property>
<property name="hibernate.connection.username">username</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

My application is running properly but I am not sure whether it is a good practise to define the db connections in both the files. Is there a way to define the db connection in a single place. Please correct me if I am wrong.

Ronald Randon
  • 1,141
  • 3
  • 13
  • 19
  • What happens when you remove the hibernate.cfg.xml file? Play 1 manages Hibernate internally, you basically don't need any additional configuration files. other than that, do what the manual tells you to do and not what you yourself guess you need to do. – Gimby Apr 04 '14 at 11:10
  • I tried to remove the hibernate.cfg.xml file and run the application. I am getting the following error, Caused by: org.hibernate.HibernateException: /hibernate.cfg.xml not found. If I remove this file, then where I need to give the mapping informations. i.e mapping of the model classes – Ronald Randon Apr 04 '14 at 11:21

1 Answers1

1

You don't need a Hibernate mapping file. Mapping is specified using JPA annotations on your model classes.

Have a read of the guide to get started.

ct_
  • 2,269
  • 1
  • 16
  • 28