tinku
tinku

Reputation: 341

Hibernate does not create table?

I am working on a spring + hibernate based project. Actually, A project is given to me with Simple Spring Web Maven Structure (Spring Tool Suit as IDE).

I have successfully imported the project into my STS IDE and have also changed some of hibernate configuration properties so that application will be able to talk to my local PostGreSQL server.

The changes that I have made are as given below:

jdbc.driverClassName=org.postgresql.Driver
jdbc.dialect=org.hibernate.dialect.PostgreSQLDialect
jdbc.databaseurl=jdbc:postgresql://localhost:5432/schema
jdbc.username=username
jdbc.password=password

The hibernate.hbm2ddl.auto property is already set to update so I didn't change that.

Then I simply deploy my project to Pivotal Server and hibernate get executed and creates around 36 tables inside my DB schema. Looks fine !

My Problem: In my hibernate.cfg.XML file total 100 Java model classes are mapped and they also have @Entity annotation. Then, why hibernate is not creating all the remaining tables?

Due to some cause I can't post the code of any of the model class here, I have searched a lot about the problem and applied many different solutions but didn't worked. Could someone please let me know that what could be the reasons that hibernate can react like this?

One of my model class which is not created in my DB.

@Entity
@Table(name = "fare_master")
public class FareMaster {
@Id
@Column(name = "fare_id")
@GeneratedValue
private int fareId;

@Column(name = "base_fare_amount")
private double baseFareAmount;

public int getFareId() {
    return fareId;
}

public void setFareId(int fareId) {
    this.fareId = fareId;
}

public double getBaseFareAmount() {
    return baseFareAmount;
}

public void setBaseFareAmount(double baseFareAmount) {
    this.baseFareAmount = baseFareAmount;
}

}

And mapping of the class is as follows

<mapping class="com.mypackage.model.FareMaster" />

Upvotes: 0

Views: 4699

Answers (3)

A. Berk
A. Berk

Reputation: 305

If you have a schema.sql file under your projects, hibernate does not create tables.

Please remove it and try again.

Upvotes: 0

FuSsA
FuSsA

Reputation: 4297

Change hibernate.hbm2ddl.auto property to create-drop if you want to create tables, setting it to update will just allow you to update existing tables in your DB.

And check your log file to catch errors.

Upvotes: 3

tinku
tinku

Reputation: 341

After a very long time efforts, I came to a conclusion that for this problem or similar type of other problems we should always follow the basic rules

1.) First, Be sure about your problem that means the Exact Issue causing this type of error.

2.) And to find out the exact issue use Logger in your application and you will definitely save lot of time.

In my case this is happening becasue I have switched my DB from MySql to PostGreSql and some of syntax in columnDefinition( a parameterin in @Column Annotation) was not compatible with my new DB. As I used again MySql everything worked fine.

Upvotes: 0

Related Questions