Reputation: 5192
I have these three tables.
want to make pojo class and hibernate configuration files but confused in relationship.
any help would be appriciate..
CREATE TABLE preprinttemplates (
PRT_ID BIGINT(20) NOT NULL AUTO_INCREMENT,
T_NAME VARCHAR(255),
UPDATED_BY BIGINT(20) NULL,
PRIMARY KEY (PRT_ID),
CONSTRAINT FK_User FOREIGN KEY FK_User (UPDATED_BY)
REFERENCES user (USER_ID)
)
ENGINE = InnoDB
PACK_KEYS = 1;
CREATE TABLE preprintsubtemplates (
PRT_SUB_ID BIGINT(20) NOT NULL AUTO_INCREMENT,
PRT_ID BIGINT(20) NOT NULL,
T_ID BIGINT(20) NOT NULL DEFAULT 0,
PRIMARY KEY (PRT_SUB_ID),
CONSTRAINT FK_1 FOREIGN KEY FK_1 (T_ID)
REFERENCES templates (T_ID),
CONSTRAINT FK_2 FOREIGN KEY FK_2 (PRT_ID)
REFERENCES preprinttemplates (PRT_ID)
)
ENGINE = InnoDB;
CREATE TABLE templates (
T_ID BIGINT(20) NOT NULL AUTO_INCREMENT,
T_NAME VARCHAR(255),
PRIMARY KEY (T_ID)
)
Upvotes: 0
Views: 360
Reputation: 130
You can write pojo class and drectly map into database
code will be like this..
@Entity
@Table(name = "preprinttemplates")
public class PrintTemplateModel {
@Id
@GeneratedValue
@Column(name = "PRT_ID")
private int PRT_ID;
@Column(name = "T_NAME")
private String T_NAME;
@Column(name = "UPDATED_BY")
private int UPDATED_BY;
}
then generate getters and setters for this class. hope this will help you.
Upvotes: 0
Reputation: 309008
Looks like two parent-child, 1:m relationships to me: template->pre-print template and pre-print template->pre-print sub-template.
So you'll have three Java classes. The ones for Template
and PrePrintTemplate
will have children List<PrePrintTemplate>
and List<PrePrintSubTemplate>
, respectively.
Upvotes: 1
Reputation: 299208
You can use Hibernate Tools to generate Hibernate Entities from a DB Schema (via Eclipse or Ant)
Upvotes: 3