RichC
RichC

Reputation: 73

Hibernate tables from pojo classes

I wonder if anybody can help.

I have a class structure that I am working on and I would like to generate the sql tables and mapping files from these classes. Is it possible?

Upvotes: 2

Views: 1360

Answers (2)

Nicola Baldissin
Nicola Baldissin

Reputation: 94

Yes, you can. You need:

  1. hibernate.cfg.xml with this line

    create More info here: Hibernate hbm2ddl.auto possible values and what they do? and here: http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/session-configuration.html

  2. you need to map the class: there are 2 ways: with annotation or hbm files. Here some about mapping: http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/mapping.html .

In the mapping you need to describe name table, catalog and (if you want) column.

Upvotes: 2

Mikko Maunu
Mikko Maunu

Reputation: 42094

It is impossible. Hibernate does not contains such a tool. It is also not that straight forward operation, because tool would not have needed information. For example with following class, there is no way to figure out should field1 or field2 to be primary key, or should table perhaps have composite key:

public class SomeClass {
    private int field1;
    private int field2;        
...
}

Upvotes: 0

Related Questions