I need to create a simple application using these tables:
http://stackoverflow.com/questions/2612848/are-these-tables-respect-the-3nf-database-normalization
I have created the application using simple old JDBC, but I would like to see how the application would look like using Hibernate, but I don't know how to put the sql code in java. I have found LOTS of examples, but I'm pretty much confused about using Hibernate and I don't know If I made such a good joob.
For example, for the first three tables:
AUTHOR table
* Author_ID, PK
* First_Name
* Last_Name
TITLES table
* TITLE_ID, PK
* NAME
* Author_ID, FK
DOMAIN table
* DOMAIN_ID, PK
* NAME
* TITLE_ID, FK
The code in java:
Table 1
@Entity
@Table(name = "AUTHORS", schema = "LIBRARY")
public class Author{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "Author_ID")
private int authorId;
@Column(name = "First_Name", nullable = false, length = 50)
private String firstName;
@Column(name = "Last_Name", nullable = false, length = 40)
private String lastName;
@OneToMany
@JoinColumn(name = "Title_ID")
private List<Title> titles;
Table 2
@Entity
@Table(name = "TITLES")
public class Title{
@Id
@Column(name = "Title_ID")
private int titleID;
@Column(name = "Name", nullable = false, length = 50)
private String name;
@ManyToOne
@JoinColumn(name = "Domain_ID")
private Domain domains;
Table 3
@Entity
@Table(name = "DOMAINS")
public class Domain{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "Domain_ID")
private int Domain_ID;
@Column(name = "Name", nullable = false, length = 50)
private String name;
@OneToOne(mappedBy = "domains")
private Title title;
}
Any good? :)