aspose file tools*
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
Author

Automatic table creation

Marton Istvan
Greenhorn

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:

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

@Id
@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
Rancher

Joined: Mar 09, 2009
Posts: 600
Marton:

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.

John.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Automatic table creation