-1

I'm trying to create database schema on application server startup.
I use hebernate 4.1.9 with annotations and hibernate.cfg.xml for configuration.

So the problem is that I cann't fully understand what I should do to create schema and after that use it in application. Of course I want to perform schema creation only on first start and on the next start I want to update it.

I'm trying to use hbn2ddl.auto in update state, but database doesn't creates. May be I should use somethin like INIT=create schema IF NOT EXISTS myschema in the end of the hibernate.connection.url??

Also I have an exception

org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not set

But in hibernate.cfg.xml there is such string:

<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>

Can anybody describe it to me?

DataNucleus
  • 15,497
  • 3
  • 32
  • 37
Anatoly
  • 1,551
  • 4
  • 21
  • 40
  • Try looking at [this question](http://stackoverflow.com/questions/12373944/how-to-create-database-schema-with-hibernate-cfg-xml) and the link within its answer. – Toddius Zho Apr 01 '13 at 18:28
  • I saw the link in the answer before, but it doesn't help because I don't want to right additional creation script and adding INIT block to the url won't create the schema. Actually I'm trying to understand why? – Anatoly Apr 01 '13 at 18:48
  • The Hibernate documentation defines **hibernate.connection.url** merely as the JDCB URL. The [MySQL Connector/J reference](http://dev.mysql.com/doc/refman/5.5/en/connector-j-reference-configuration-properties.html) doesn't define an **INIT** property. I believe the point of the linked article to be you have to bite the bullet and at least create an empty schema yourself. – Toddius Zho Apr 01 '13 at 21:52
  • I solve the problem. Connector/J documentation doesn't define an INIT property, yes it's truth. But it defines createDatabase property. – Anatoly Apr 02 '13 at 06:24

1 Answers1

2

I solve the problem by myself. I should add createDatabase=true to hibernate.connection.url

Anatoly
  • 1,551
  • 4
  • 21
  • 40