Ich erhalte die Fehlermeldung „JDBC-Batch-Update konnte nicht ausgeführt werden“, wenn ich den Ruhezustand „Many to ManyJava

Java-Forum
Anonymous
 Ich erhalte die Fehlermeldung „JDBC-Batch-Update konnte nicht ausgeführt werden“, wenn ich den Ruhezustand „Many to Many

Post by Anonymous »

Ich habe in Hibernate eine „Frage-Tag“-Viele-zu-Viele-Beziehung konfiguriert.
Wenn ich es mit einem kleinen Programm teste, erscheint die folgende Fehlermeldung:
(Meine Hibernate-Version ist 3.1)

Code: Select all

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Hibernate: insert into javaqa2.qa_tag (creator_id, name, description, create_date, used_cnt) values (?, ?, ?, ?, ?)
Hibernate: insert into javaqa2.qa_tag (creator_id, name, description, create_date, used_cnt) values (?, ?, ?, ?, ?)
Hibernate: insert into javaqa2.qa_question (creator_id, subject, content, creator_ip, question_tags, upvote_cnt, downvote_cnt, visit_cnt, answer_cnt, comment_cnt, istopmost, islocked, isanonym, create_date) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into qa_question_tags (question_id, tag_id) values (?, ?)
Hibernate: insert into qa_question_tags (question_id, tag_id) values (?, ?)
Exception in thread "main" org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:143)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at test.Test1.main(Test1.java:49)
Caused by: java.sql.BatchUpdateException: No database selected
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1669)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1085)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
... 8 more
Dies ist mein Testprogramm:
öffentliche Klasse Test1 {

Code: Select all

public static void main(String[] args) {
Configuration cfg=new Configuration().configure();
SessionFactory sf=cfg.buildSessionFactory();
Session session = sf.openSession();
Transaction trans = session.beginTransaction();

Student student = (Student)session.load(Student.class, Integer.valueOf(45));
Question question=new Question(student, "test8881","test8882",
"192.168,88.88","Java,dotNet,Struts2",  0,0,0,0,0,
Boolean.FALSE, Boolean.FALSE, Boolean.FALSE,
new Date());
Tag tag1=new Tag(student,"test tag1","test tag1",new Date(),0);
Tag tag2=new Tag(student,"test tag2","test tag2",new Date(),0);

session.save(tag1);
session.save(tag2);

Set tagList =new HashSet();
tagList.add(tag1);
tagList.add(tag2);

question.setTags(tagList); // when add this line... error occurs

session.save(question);
trans.commit();
}
Dieses Programm läuft gut, wenn die Methode setTags(tagList) nicht für eine Frage aufgerufen wird.
Wenn ich jedoch diesen Methodenaufruf hinzufüge, tritt der Fehler auf. (siehe Kommentar im Programm).


Dies ist der Teil von Question.hbm.xml, der Many-to-Many-Eigenschaften definiert.

Code: Select all

    



Ich habe die folgende Eigenschaft in meiner hibernate.cfg.xml festgelegt, um sicherzustellen, dass die Tabelle automatisch aktualisiert wird.

Code: Select all

 update 
Ich war mit der Fehlermeldung verwechselt, und sagen Sie mir bitte, wo das Falsche ist?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post