Когда я тестирую его с помощью небольшой программы, возникает следующая ошибка:
(Моя версия Hibernate — 3.1)
Код: Выделить всё
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
public class Test1 {
Код: Выделить всё
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();
}
однако, когда я добавляю вызов этого метода, возникает ошибка. (см. комментарий в программе).
Это часть файла Question.hbm.xml, определенная в свойствах типа «многие-ко-многим».
Код: Выделить всё
Код: Выделить всё
update