浏览 2867 次
锁定老帖子 主题:第一个hibernate例子失败
该帖已经被评为新手帖
|
|
---|---|
作者 | 正文 |
发表时间:2007-10-18
最后修改:2009-01-12
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Mapping file autogenerated by MyEclipse Persistence Tools --> <hibernate-mapping> <class name="com.lee.hibernate.User" table="user" catalog="test"> <composite-id name="id" class="com.lee.hibernate.UserId"> <key-property name="id" type="java.lang.Integer"> <column name="ID" /> </key-property> <key-property name="name" type="java.lang.String"> <column name="NAME" length="50" /> </key-property> <key-property name="password" type="java.lang.String"> <column name="PASSWORD" length="50" /> </key-property> <key-property name="firstName" type="java.lang.String"> <column name="FIRST_NAME" length="50" /> </key-property> <key-property name="lastName" type="java.lang.String"> <column name="LAST_NAME" length="50" /> </key-property> <key-property name="dateCreated" type="java.util.Date"> <column name="DATE_CREATED" length="0" /> </key-property> </composite-id> </class> </hibernate-mapping> 程序运行后显示 log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment). log4j:WARN Please initialize the log4j system properly. Exception in thread "main" java.lang.ClassCastException: java.lang.Integer at org.hibernate.type.ComponentType.toLoggableString(ComponentType.java:377) at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:112) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187) at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172) at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70) at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535) at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523) at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519) at com.lee.hibernate.UserDAO.save(UserDAO.java:30) at com.lee.hibernate.HibernateExample.addUser(HibernateExample.java:22) at com.lee.hibernate.HibernateExample.main(HibernateExample.java:8) 大哥们帮忙! 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2007-10-18
在src里面添加log4j.properties
内容是: log4j.rootLogger=WARN, Console log4j.appender.Console=org.apache.log4j.ConsoleAppender log4j.appender.Console.layout=org.apache.log4j.PatternLayout log4j.appender.Console.layout.ConversionPattern=(%r ms) [%t] %-5p: %c#%M %x: %m%n log4j.logger.com.genuitec.eclipse.sqlexplorer=DEBUG log4j.logger.org.apache=WARN log4j.logger.org.hibernate=WARN |
|
返回顶楼 | |
发表时间:2007-10-18
java.lang.ClassCastException: java.lang.Integer
|
|
返回顶楼 | |
发表时间:2007-11-16
为什么只在修改操作的时候才出现这个问题呢??
|
|
返回顶楼 | |