我对hibernate非常新...我想使用hibernate映射注释但不知道如何使用那些..我已经阅读了一些文章但仍然困惑......这些是我的模型类..
@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public abstract class User {
public User() {
// TODO Auto-generated constructor stub
}
@Id
private int id;
private String name;
private Date date;
private char gender;
private char isMarried;
private String password;
private char status;
@OneToOne
@PrimaryKeyJoinColumn
Contact contact;
public User(int id, String name, Date date, char gender, char isMarried,
String password, char status) {
super();
this.id = id;
this.name = name;
this.date = date;
this.gender = gender;
this.isMarried = isMarried;
this.password = password;
this.status = status;
}
public int getId() {
return id;
}
public Contact getContact() {
return contact;
}
public void setContact(Contact contact) {
this.contact = contact;
}
public String getName() {
return name;
}
public Date getDate() {
return date;
}
public char getGender() {
return gender;
}
public char getIsMarried() {
return isMarried;
}
public String getPassword() {
return password;
}
public char getStatus() {
return status;
}
public boolean validate(String password) {
if (this.getPassword().equals(password)) {
return true;
}
return false;
}
public void changePassword(String newPassword)
{
if(this.validate(getPassword()))
{
System.out.println(password);
this.password=newPassword;
System.out.println(password);
}
}
}
@Entity
public class Customer extends User{
public Customer() {
// TODO Auto-generated constructor stub
}
private String occupation;
public Customer(int id, String name, Date date, char gender,
char isMarried, String password, char status) {
super(id, name, date, gender, isMarried, password, status);
// TODO Auto-generated constructor stub
}
public String getOccupation() {
return occupation;
}
}
@Entity
public class Contact {
@Id
int id;
String email;
String mobile;
String city;
String pin;
String address;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getPin() {
return pin;
}
public void setPin(String pin) {
this.pin = pin;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
ublic class Account {
private long accId;
private double sum;
public long getAccId() {
return accId;
}
public void setAccId(long accId) {
this.accId = accId;
}
public double getSum() {
return sum;
}
public void setSum(double sum) {
this.sum = sum;
}
}
public class Payee {
int id;
long accId;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public long getAccId() {
return accId;
}
public void setAccId(long accId) {
this.accId = accId;
}
}
数据库查询应该像这些......
CREATE TABLE `account` (
`accId` int(11) NOT NULL auto_increment,
`sum` float NOT NULL,
`owner_id` int(11) default NULL,
PRIMARY KEY (`accId`),
KEY `FK1D0C220DBB52EA6F` (`owner_id`),
CONSTRAINT `FK1D0C220DBB52EA6F` FOREIGN KEY (`owner_id`) REFERENCES `customer` (`id`)
);
CREATE TABLE `contact` (
`id` int(11) NOT NULL auto_increment,
`address` varchar(255) default NULL,
`city` varchar(255) default NULL,
`email` varchar(255) default NULL,
`mobile` varchar(255) default NULL,
`pin` varchar(255) default NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE `customer` (
`id` int(11) NOT NULL,
`dob` datetime default NULL,
`gender` varchar(255) default NULL,
`married` varchar(255) default NULL,
`name` varchar(255) default NULL,
`password` varchar(255) default NULL,
`status` varchar(255) default NULL,
`contact_id` int(11) default NULL,
`occupation` varchar(255) default NULL,
PRIMARY KEY (`id`),
KEY `FK285FEB4AFD7C1027fbe3fe` (`contact_id`),
CONSTRAINT `FK285FEB4AFD7C1027fbe3fe` FOREIGN KEY (`contact_id`) REFERENCES `contact` (`id`)
);
CREATE TABLE `payee` (
`id` int(11) NOT NULL auto_increment,
`accId` int(11) NOT NULL,
`payer_id` int(11) default NULL,
PRIMARY KEY (`id`),
KEY `FK4954328AA304E8D` (`payer_id`),
CONSTRAINT `FK4954328AA304E8D` FOREIGN KEY (`payer_id`) REFERENCES `customer` (`id`)
);
请任何人帮忙....我的模型类中的注释应该是什么......