-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Hibernate create tables,column order and indexes
PostPosted: Thu Sep 23, 2010 7:54 am 
Newbie

Joined: Thu Sep 23, 2010 7:52 am
Posts: 1
I have this setting in the hibernate.cfg.xml


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

and defined a class like this

Code:
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

import org.hibernate.annotations.Index;
import org.hibernate.annotations.Table;


@Entity
@javax.persistence.Table(name="testtable")
@Table(appliesTo="testtable",indexes={@Index(name="idx",columnNames={"edad","nombre"})})

public class Prueba extends model {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private long serial;
   
    private String nombre;
   
    private int edad;
...
   


I want to create the table at the start of the process.

But If I don't put the javax.persistence annotation, I get an exception telling me that table points to an unknown table.

Also I'd like to create the table with the columns in that order. but the table is generated with its columns in alphabetical order. (If it's pre-generated the order is respected,but I don't have that posibility)

Also Indexes are not being created.

What could be happening here?

I use Hibernate annotations 3.4.0.GA and Mysql 5.1.46


Top
 Profile  
 
 Post subject: Re: Hibernate create tables,column order and indexes
PostPosted: Sat Sep 25, 2010 2:56 am 
Newbie

Joined: Wed Jun 18, 2008 9:17 am
Posts: 12
Hi

Run your code with debug log level you will then see what Hibernate is doing. Post the log if you want.

I tried your example and my setup works correctly.

My columns were created in the order defined in the Entity class. Order in which columns are created can be affected by few things:
a. what ever is generating create sql statement might be ordering the column. Need to check the API for Hibernate
b. database could be configured to place columns in the alphabetical order ( not sure if this can be done in mysql but is possible) but I reckon your issue is due to (a) above. Find out which class creates the schema and see if there is any property to turn this off.

I am using Spring3 with Hibernate EntityManager 3.2.1.GA.

In my environment everything worked as you were expecting including the index creation.


Also check mysql user has permission to create indexes.


Top
 Profile  
 
 Post subject: Re: Hibernate create tables,column order and indexes
PostPosted: Sat Sep 25, 2010 8:43 am 
Newbie

Joined: Tue Jul 20, 2010 1:53 am
Posts: 18
<property name="hibernate.hbm2ddl.auto">create</property> then only in Database create table and <mapping class="<pojo class or(table name)>"> use this property.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.