我正在使用hibernate 4和Maven:
package tn.onp.mvno.model;
@Entity
@Table(name="PERSON")
public class Person {
private int id;
private String name;
private String surname;
private String email;
private String adresse;
private String MobilePhone;
/**
* Get User Id
*
* @return int - User Id
*/
@Id
@GeneratedValue
@Column(name="ID")
public int getId() {
return id;
}
/**
* Set User Id
*
* @param int - User Id
*/
public void setId(int id) {
this.id = id;
}
}
package tn.onp.mvno.model;
@Entity
@Inheritance(strategy= InheritanceType.TABLE_PER_CLASS)
@Table(name="USER")
public class User extends Person{
private String SIMCardNumber;
private String SIMCardValidityDate;
private Collection<Call> calls;
private Collection<Credit> credits;
@Column(name="SIMCARDNUMBER", unique = true, nullable = false)
public String getSIMCardNumber() {
return SIMCardNumber;
}
public void setSIMCardNumber(String sIMCardNumber) {
SIMCardNumber = sIMCardNumber;
}
@Column(name="SIMCARDVALIDITYDATE", nullable = false)
public String getSIMCardValidityDate() {
return SIMCardValidityDate;
}
public void setSIMCardValidityDate(String sIMCardValidityDate) {
SIMCardValidityDate = sIMCardValidityDate;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
public Collection<Call> getCalls() {
return calls;
}
public void setCalls(Collection<Call> calls) {
this.calls = calls;
}
}
Call.java
@Entity
@Table(name="CALL")
public class Call {
private String callId;
private String telNumber;
private String term;
private String duration;
private String direction;
private User user;
/** Get the callId
* @return the callId
*/
@Id
@GeneratedValue
@Column(name="CALLID")
public String getCallId() {
return callId;
}
/** Set the callId
* @param callId the callId to set
*/
public void setCallId(String callId) {
this.callId = callId;
}
/** Get the telNumber
* @return the telNumber
*/
@Column(name="TELNUMBER")
public String getTelNumber() {
return telNumber;
}
/** Set the telNumber
* @param telNumber the telNumber to set
*/
public void setTelNumber(String telNumber) {
this.telNumber = telNumber;
}
/** Get the term
* @return the term
*/
@Column(name="TERM")
public String getTerm() {
return term;
}
/** Set the term
* @param term the term to set
*/
public void setTerm(String term) {
this.term = term;
}
/** Get the duration
* @return the duration
*/
@Column(name="DURATION")
public String getDuration() {
return duration;
}
/** Set the duration
* @param duration the duration to set
*/
public void setDuration(String duration) {
this.duration = duration;
}
/** Get the direction
* @return the direction
*/
@Column(name="DIRECTION")
public String getDirection() {
return direction;
}
/** Set the direction
* @param direction the direction to set
*/
public void setDirection(String direction) {
this.direction = direction;
}
/** Get the user
* @return the user
*/
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id")
public User getUser() {
return user;
}
/** Set the user
* @param user the user to set
*/
public void setUser(User user) {
this.user = user;
}
}
当我在tomcat服务器上部署应用程序并运行它时,我收到此错误:
INFO: HHH000227: Running hbm2ddl schema export
Hibernate: alter table CALL drop foreign key FK1F725EE04824FE
févr. 11, 2013 5:53:38 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: HHH000389: Unsuccessful: alter table CALL drop foreign key FK1F725EE04824FE
févr. 11, 2013 5:53:38 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'CALL drop foreign key
FK1F725EE04824FE' at line 1
Hibernate: drop table if exists CALL
févr. 11, 2013 5:53:38 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: HHH000389: Unsuccessful: drop table if exists CALL
févr. 11, 2013 5:53:38 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'CALL' at line 1
Hibernate: drop table if exists CREDIT
Hibernate: drop table if exists PERSON
Hibernate: create table CALL (CALLID varchar(255) not null auto_increment, DIRECTION
varchar(255), DURATION varchar(255), TELNUMBER varchar(255), TERM varchar(255), id
integer, primary key (CALLID))
févr. 11, 2013 5:53:38 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: HHH000389: Unsuccessful: create table CALL (CALLID varchar(255) not null
auto_increment, DIRECTION varchar(255), DURATION varchar(255), TELNUMBER varchar(255),
TERM varchar(255), id integer, primary key (CALLID))
févr. 11, 2013 5:53:38 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'CALL (CALLID varchar(255) not
null auto_increment, DIRECTION varchar(255), DURAT' at line 1