我试图使用休眠注释将这两个类保留在oracle数据库中,并且出现这些错误。
我还有另外两个相同的类,并且可以将它们添加到数据库中,但是这一次出现了这些错误。
事件类:
package Q3;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Table;
@Entity
@Table(name="events")
public class Event {
@Id
@Column(name="e_id" ,unique=true,nullable=false)
private int e_id;
@Column(name="event_name")
String event_name;
@ElementCollection
@CollectionTable(name="feedbacks",joinColumns=@JoinColumn(name="event_id"))
@Column(name="feed")
private Set<String> feedback;
public Event(int event_id, String event_name) {
super();
this.e_id = event_id;
this.event_name = event_name;
}
public int getEvent_id() {
return e_id;
}
public void setEvent_id(int event_id) {
this.e_id = event_id;
}
public String getEvent_name() {
return event_name;
}
public void setEvent_name(String event_name) {
this.event_name = event_name;
}
public Set<String> getFeedback() {
return feedback;
}
public void setFeedback(Set<String> feedback) {
this.feedback = feedback;
}
}
package Q3;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="feedbacks")
public class Feedback {
@Id
@Column(name="f_id",unique=true,nullable=false)
private int f_id;
@Column(name="feedback")
private String feedback;
@Column(name="event_id")
private int event_id;
public Feedback(int f_id, String feedback, int event_id) {
super();
this.f_id = f_id;
this.feedback = feedback;
this.event_id = event_id;
}
public int getF_id() {
return f_id;
}
public void setF_id(int f_id) {
this.f_id = f_id;
}
public String getFeedback() {
return feedback;
}
public void setFeedback(String feedback) {
this.feedback = feedback;
}
public int getEvent_id() {
return event_id;
}
public void setEvent_id(int event_id) {
this.event_id = event_id;
}
}
EventMain类
package Q3;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
public class EventMain {
public static void main(String[] args) {
AnnotationConfiguration config=new AnnotationConfiguration();
SessionFactory sf=config.configure
("hibernate1.cfg.xml").buildSessionFactory();
Session ses=sf.openSession();
Transaction tx=ses.beginTransaction();
ses.beginTransaction();
Feedback feed=new Feedback(1, "It was a good event. I enjoyed it a lot.", 1);
Event e=new Event(1, "WWF");
ses.save(e);
ses.save(feed);
tx.commit();
ses.close();
}
}
错误
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Hibernate: insert into events (event_name, e_id) values (?, ?)
Exception in thread "main" org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:114)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:109)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:244)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2395)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2858)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:267)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:259)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:178)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:375)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
at Q3.EventMain.main(EventMain.java:23)
Caused by: java.sql.BatchUpdateException: ORA-00942: table or view does not exist
at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:343)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10657)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
... 15 more
这是配置文件
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">
oracle.jdbc.driver.OracleDriver
</property>
<property name="hibernate.connection.url">
jdbc:oracle:thin:@127.0.0.1:1521:ORCL
</property>
<property name="hibernate.connection.username">
hr
</property>
<property name="hibernate.connection.password">
hr
</property>
<property name="show_sql">
true
</property>
<property name="dialect">
org.hibernate.dialect.Oracle10gDialect
</property>
<property name="hibernate.hbm2ddl.auto">
update
</property>
<mapping class="Q3.Event"></mapping>
<mapping class="Q3.Feedback"></mapping>
<mapping class="Q2.Product"></mapping>
<mapping class="NEw.College"></mapping>
<mapping class="NEw.Student"></mapping>
</session-factory>
</hibernate-configuration>