谢谢,我换了个版本稍微老的hibernate 包,基本上能实现插入数据库了,不过还有点小的提示,帮忙看看。 控制台信息: log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).SessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]];ActionQueue[insertions=[] updates=[] deletions=[] collectionCreations=[] collectionRemovals=[] collectionUpdates=[]]) Hibernate: insert into news_table (title, content) values (?, ?)log4j:WARN Please initialize the log4j system properly. 上面提示什么意思?
谢谢了,有个log4j-1.2.11.jar包,是不是其他地方有什么问题。
既然show_sql都出来了,如果数据确实也修改了,那就说明框架没有问题了
又有个新问题,请帮忙看下。 package lee; import org.hibernate.Transaction; …… public class PersonManager { public static void main(String[] args) { PersonManager mgr = new PersonManager(); mgr.createAndStorePerson(); HibernateUtil.sessionFactory.close(); } private void createAndStorePerson() { Session session = HibernateUtil.currentSession(); Transaction tx = session.beginTransaction(); Person yeeku = new Person(); yeeku.setAge(29); yeeku.setName("aaa"); Map m = new HashMap(); m.put("语文" , new Float(56f)); m.put("数学" , new Float(23f)); yeeku.setScores(m); session.save(yeeku); /* Person p = (Person)session.get(Person.class , new Integer(1)); for (Iterator it = p.getSchools().iterator() ; it.hasNext() ; ) { System.out.println(it.next()); } */ tx.commit(); HibernateUtil.closeSession(); }
控制台信息:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).SessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]];ActionQueue[insertions=[] updates=[] deletions=[] collectionCreations=[] collectionRemovals=[] collectionUpdates=[]])
Hibernate: insert into news_table (title, content) values (?, ?)log4j:WARN Please initialize the log4j system properly.
上面提示什么意思?
package lee;
import org.hibernate.Transaction;
……
public class PersonManager
{ public static void main(String[] args)
{
PersonManager mgr = new PersonManager(); mgr.createAndStorePerson(); HibernateUtil.sessionFactory.close();
} private void createAndStorePerson()
{
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction(); Person yeeku = new Person(); yeeku.setAge(29);
yeeku.setName("aaa");
Map m = new HashMap();
m.put("语文" , new Float(56f));
m.put("数学" , new Float(23f));
yeeku.setScores(m); session.save(yeeku);
/*
Person p = (Person)session.get(Person.class , new Integer(1));
for (Iterator it = p.getSchools().iterator() ; it.hasNext() ; )
{
System.out.println(it.next());
} */ tx.commit();
HibernateUtil.closeSession();
}
}
运行提示:“错误启动,选择未包含main类型”
请多多指教。
重新建一个项目然后把这些代码拷过去就可以了。