Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

"hibernate.hbm2ddl.auto">create - to generate DB Tables

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hello,

I am developing a program with Hibernate and Oracle and I want to reproduce the same application using MySQL. I want to generate de database tables using:

<property name="hibernate.hbm2ddl.auto">create</property>

from the ("Oracle") domain code, but I can only create one table out of four. Does anyone have an idea what I am doing wrong?

Regards.

M. Marin.
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
We'll probably need a bit more information. Are you getting any errors?

If you can do one, then try to do just two. See if you can get two to work. Maybe even scale it back to table name and primary key for two tables. Then incrementally do more until you find the setting that might be causing the problem.

Just an approach. Any errors? Bizarre table mappings? I'm betting the three tables are dependent on each other?
 
M Marin
Ranch Hand
Posts: 32
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Thank you for the answer. I followed the instructions and It helped to locate the problem. Oracle allowed me to use the word "KEY" as a field name and MySQL did not like it, so I guess "KEY" is a reserved keyword in MySQL. So I changed the field name and now it works.

from:

@Length(max=80)
@Column(name="KEY", length=80)
public String getKey() {
return key;
}


public void setKey(String key) {
this.key = key;
}



to:

@Length(max=80)
@Column(name="PKEY", length=80)
public String getPkey() {
return pkey;
}


public void setPkey(String pkey) {
this.pkey = pkey;
}

now it works, so great. Thank you for the quick help.

M. Marin.
 
Cameron Wallace McKenzie
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Good sleuthing, Greenhorn! And thanks for the post-back. You'll be surprised by how many people will have that exact problem and have it subsequently solved by your hard work.

I know a guy that wrote an entire book using a table named "User" and a MySQL database, only to discover none of the examples worked as promised in certain databases because User is a reserved word. What a drag!

-Cameron McKenzie

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

M Marin wrote:Hello,

I am developing a program with Hibernate and Oracle and I want to reproduce the same application using MySQL. I want to generate the database tables using:

<property name="hibernate.hbm2ddl.auto">create</property>

from the ("Oracle") domain code, but I can only create one table out of four. Does anyone have an idea what I am doing wrong?

Regards.

M. Marin.



Hi,

can you please post your bean class and persistence.xml and the settings what you are using to execute this program..because I am facing the same problem and struggling for one week to create tables in database automatically.

Thanks in Advance,


Best Regards,
Raja.
 
M Marin
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I am not using persistance.xml for the project. I use hibernate.cfg.xml:

(This is a simplified version)

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">mypassword</property>
<property me="hibernate.connection.url">jdbc:mysql://localhost:3306/mydb</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.search.autoregister_listeners">false</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<property name="hibernate.show_sql">true</property>
<mapping class="data.Customer" />
</session-factory>
</hibernate-configuration>

Try whether that works

Marin
 
M Marin
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Add also the schema name manually to de database, just leave the tables to be automatically generated.
 
rajasekhar kannamaneni
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

M Marin wrote:Add also the schema name manually to de database, just leave the tables to be automatically generated.



I did what you said..but still its not creating any tables in database and its printing this on console:

10:24:07,513 INFO [SessionFactoryObjectFactory] Bound factory to JNDI name: persistence.unit:unitName=ernst-app-ear-1.0.ear/persistenceImpl-app-1.0.war#DefaultDS
10:24:07,513 WARN [SessionFactoryObjectFactory] InitialContext did not implement EventContext
10:24:07,528 INFO [SchemaUpdate] Running hbm2ddl schema update
10:24:07,528 INFO [SchemaUpdate] fetching database metadata
10:24:07,528 INFO [SchemaUpdate] updating schema
10:24:07,528 INFO [SchemaUpdate] schema update complete
10:24:07,544 INFO [NamingHelper] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}

can you please tell me what you have done other than creating hbm.xml, persistence.xml and entitiy beans..can you please check it.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator


10:24:07,528 INFO [SchemaUpdate] updating schema
10:24:07,528 INFO [SchemaUpdate] schema update complete


Looks like its updating the schema.


(NB: "entity beans" are a EJB2 technology. When you say you created entity beans did you really mean entity beans? )
 
rajasekhar kannamaneni
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Paul Sturrock wrote:


10:24:07,528 INFO [SchemaUpdate] updating schema
10:24:07,528 INFO [SchemaUpdate] schema update complete


Looks like its updating the schema.


(NB: "entity beans" are a EJB2 technology. When you say you created entity beans did you really mean entity beans? )



hi, this is my class..can you please check it..

 
rajasekhar kannamaneni
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

M Marin wrote:Add also the schema name manually to de database, just leave the tables to be automatically generated.




what I found one interesting fact is..when jboss runs persistence.xml its not generating any create table queries..thats why its not creating any tables..how to generate the create table queries automatically.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
This appears to be a duplicate. Please continue the discussion in your other topic.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic