Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Automatic table creation

 
Marton Istvan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic