File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Automatic table creation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Automatic table creation" Watch "Automatic table creation" New topic

Automatic table creation

Marton Istvan

Joined: May 02, 2009
Posts: 3
Hi all,

I would like to write a bulletin-board application with hibernate.
I thought one topic will be one table, and a message in a topic a row (with an id).

I've written this entity class:

@Table(name = "TOPIC")
public class Topic {

@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID")
private Long id;

@Column(name = "MESSAGE")
private String message;

/*constructors, getters, setters */

When I use this entity class, and the table named TOPIC doesn't exist in the database, hibernate creates it. That's OK.

But, I want hibernate to create tables for each topic that users open, and use the preceding entity class to manipulate the messages of all the topics.
How should I do it?

And, anyway... What do you think about the schema? I know it's very very simple. Is there any idea how I can improve it?

Thanks in advance!
John de Michele

Joined: Mar 09, 2009
Posts: 600

I would think a better schema would be to have a topics table, and a messages table, with a one-to-many relationship between them. It seems to me that would scale better if your board got a lot of posts and topics.

I agree. Here's the link:
subject: Automatic table creation
It's not a secret anymore!