我是学习者,我试图在mysqldb中创建一个表。 代码看起来绝对正常,但我得到以下异常。 你可以帮帮我吗。
Jul 15, 2016 9:16:06 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.0.9.Final}
Jul 15, 2016 9:16:06 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Jul 15, 2016 9:16:06 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Jul 15, 2016 9:16:07 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
Jul 15, 2016 9:16:07 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
Jul 15, 2016 9:16:08 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/sakila]
Jul 15, 2016 9:16:08 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=sidMa, password=****}
Jul 15, 2016 9:16:08 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
Jul 15, 2016 9:16:08 AM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Fri Jul 15 09:16:09 EDT 2016 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Jul 15, 2016 9:16:09 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
Jul 15, 2016 9:16:10 AM org.hibernate.search.engine.Version <clinit>
INFO: HSEARCH000034: Hibernate Search 5.5.4.Final
Jul 15, 2016 9:16:12 AM org.hibernate.search.engine.impl.ConfigContext getLuceneMatchVersion
WARN: HSEARCH000075: Configuration setting hibernate.search.lucene_version was not specified: using LUCENE_CURRENT.
printingStudentInfo [stuNumber=null, stuName=null, StudentAddress=null, classRegistered=null, phoneNumber=null]
printingStudentInfo [stuNumber=null, stuName=sid, StudentAddress=StudentAddress [houseNo=135, streetName=rose, cityName=toronto, state=ontario, country=canada, postalCode=41100], classRegistered=Computer Science Engineering, phoneNumber=9866869877]
Hibernate: select max(Roll_Number) from StudentData
Jul 15, 2016 9:16:12 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 1146, SQLState: 42S02
Jul 15, 2016 9:16:12 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Table 'sakila.studentdata' doesn't exist
org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:95)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:79)
at org.hibernate.id.IncrementGenerator.initializePreviousValueHolder(IncrementGenerator.java:113)
at org.hibernate.id.IncrementGenerator.generate(IncrementGenerator.java:52)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:101)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:192)
at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:38)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:177)
at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:32)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:73)
at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:679)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:671)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:666)
at com.rogers.managementsystem.operationsmodel.StudDataOperations.stuInsert(StudDataOperations.java:94)
at com.rogers.managementsystem.coremodel.StudentManagementSystem.main(StudentManagementSystem.java:58)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'sakila.studentdata' doesn't exist
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
at com.mysql.jdbc.Util.getInstance(Util.java:387)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:942)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3966)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3902)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2526)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2673)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2549)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1962)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:70)
... 13 more
和持久化类如下
@Entity
@Table(name="StudentData")
public class StudentInfo {
private Integer stuNumber;
private String stuName;
private StudentAddress StudentAddress;
private String classRegistered;
private Long phoneNumber;
public StudentInfo() {
super();
}
public StudentInfo(Integer stuNumber, String stuName, StudentAddress StudentAddress, String classRegistered, Long phoneNumber) {
super();
this.stuNumber = stuNumber;
this.stuName = stuName;
this.StudentAddress = StudentAddress;
this.classRegistered = classRegistered;
this.phoneNumber = phoneNumber;
}
@Id
@GeneratedValue(generator="increment")
@GenericGenerator(name="increment",strategy="increment")
@Column(name="Roll_Number", length = 10)
public Integer getStuNumber() {
return stuNumber;
}
@Column(name="Student_Name")
public String getStuName() {
return stuName;
}
@Embedded
//@JoinColumn(name="Address")
public StudentAddress getStudentAddress() {
return StudentAddress;
}
@Column(name="subject_name")
public String getClassRegistered() {
return classRegistered;
}
@Column(name="Phone_N0")
public Long getPhoneNumber() {
return phoneNumber;
}
public void setStuNumber(Integer stuNumber) {
this.stuNumber = stuNumber;
}
public void setStuName(String stuName) {
this.stuName = stuName;
}
public void setStudentAddress(StudentAddress studentAddress) {
StudentAddress = studentAddress;
}
public void setClassRegistered(String classRegistered) {
this.classRegistered = classRegistered;
}
public void setPhoneNumber(Long phoneNumber) {
this.phoneNumber = phoneNumber;
}
@Basic
public static final Integer toTheTotal = 600;
@Override
public String toString() {
return "StudentInfo [stuNumber=" + stuNumber + ", stuName=" + stuName+ ", StudentAddress=" + StudentAddress + ", classRegistered=" + classRegistered
+ ", phoneNumber=" + phoneNumber + "]";
}
}
embeddable类如下:
@Embeddable
@Table(name="Address")
public class StudentAddress {
private Integer houseNo;
private String streetName;
private String cityName;
private String state;
private String country;
private Long postalCode;
public StudentAddress() {
super();
}
public StudentAddress(Integer houseNo, String streetName, String cityName, String state, String country,
Long postalCode) {
super();
this.houseNo = houseNo;
this.streetName = streetName;
this.cityName = cityName;
this.state = state;
this.country = country;
this.postalCode = postalCode;
}
@Column(name="HNo")
public Integer getHouseNo() {
return houseNo;
}
@Column(name="street_Name")
public String getStreetName() {
return streetName;
}
@Column(name="city_Name")
public String getCityName() {
return cityName;
}
@Column(name="state")
public String getState() {
return state;
}
@Column(name="country")
public String getCountry() {
return country;
}
@Column(name="postal_code")
public Long getPostalCode() {
return postalCode;
}
public void setHouseNo(Integer houseNo) {
this.houseNo = houseNo;
}
public void setStreetName(String streetName) {
this.streetName = streetName;
}
public void setCityName(String cityName) {
this.cityName = cityName;
}
public void setState(String state) {
this.state = state;
}
public void setCountry(String country) {
this.country = country;
}
public void setPostalCode(Long postalCode) {
this.postalCode = postalCode;
}
@Override
public String toString() {
return "StudentAddress [houseNo=" + houseNo + ", streetName=" + streetName + ", cityName=" + cityName
+ ", state=" + state + ", country=" + country + ", postalCode=" + postalCode + "]";
}
}
我的hibernate.cfg.xml文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration SYSTEM
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/sakila</property>
<property name="hibernate.connection.username">sidMa</property>
<property name="hibernate.connection.password">*****</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cahce.internal.NoCacheProvider</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.id.new_generator_mappings"></property>
<property name="hbm2ddl.quto">create</property>
<mapping class="com.rogers.managementsystem.student.StudentInfo"/>
</session-factory>
</hibernate-configuration>
我的会话如下:
config = new Configuration();//.addAnnotatedClass(StudentInfo.class);
config.configure("hibernate.cfg.xml");
session = config.buildSessionFactory().openSession();
请帮助我理解我在哪里做错了。