锁定老帖子 主题:配置错误请教
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2003-11-21
2003-10-24 9:53:16 net.sf.hibernate.util.JDBCExceptionReporter logExceptions 警告: SQL Error: 0, SQLState: S1009 2003-10-24 9:53:16 net.sf.hibernate.util.JDBCExceptionReporter logExceptions 严重: Invalid value for getLong() - 'p' 2003-10-24 9:53:16 net.sf.hibernate.util.JDBCExceptionReporter logExceptions 警告: SQL Error: 0, SQLState: S1009 2003-10-24 9:53:16 net.sf.hibernate.util.JDBCExceptionReporter logExceptions 严重: Invalid value for getLong() - 'p' 2003-10-24 9:53:16 net.sf.hibernate.JDBCException <init> 严重: could not insert: [gigix.forum.bean.Post] java.sql.SQLException: Invalid value for getLong() - 'p' at com.mysql.jdbc.ResultSet.getLong(ResultSet.java:1420) at net.sf.hibernate.id.IdentifierGeneratorFactory.get(IdentifierGeneratorFactory.java:29) at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:574) at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:488) at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:803) at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:678) at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1324) at net.sf.hibernate.engine.Cascades$4.cascade(Cascades.java:113) at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:339) at net.sf.hibernate.engine.Cascades.cascadeCollection(Cascades.java:429) at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:355) at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:406) at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:385) at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:824) at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:678) at UserHibernate.main(UserHibernate.java:38) Exception in thread "main" net.sf.hibernate.JDBCException: could not insert: [gigix.forum.bean.Post] at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:594) at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:488) at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:803) at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:678) at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1324) at net.sf.hibernate.engine.Cascades$4.cascade(Cascades.java:113) at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:339) at net.sf.hibernate.engine.Cascades.cascadeCollection(Cascades.java:429) at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:355) at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:406) at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:385) at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:824) at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:678) at UserHibernate.main(UserHibernate.java:38) Caused by: java.sql.SQLException: Invalid value for getLong() - 'p' at com.mysql.jdbc.ResultSet.getLong(ResultSet.java:1420) at net.sf.hibernate.id.IdentifierGeneratorFactory.get(IdentifierGeneratorFactory.java:29) at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:574) ... 13 more [root@huili src]# 为啥错了?最后的13是啥意思? 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2003-11-21
检查一下数据嘛,这个错误是把一个值为‘P’的当成Long来拿了。应该比较好排除的。
|
|
返回顶楼 | |
发表时间:2003-11-21
to squirrel
帮忙看一下哪儿错了哦,找了半天没找到!先谢了!!! //////////////////UserHibernate.java import gigix.forum.bean.Post; import gigix.forum.bean.User; import net.sf.hibernate.Query; import net.sf.hibernate.Session; import net.sf.hibernate.SessionFactory; import net.sf.hibernate.cfg.Configuration; import net.sf.hibernate.tool.hbm2ddl.SchemaExport; /* * Created on 2003-7-17 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ /** * @author administrator * 2003 2003-7-17 22:55:30 * Forum: */ public class UserHibernate { public static void main(String[] args) throws Exception{ Configuration cfg = new Configuration().addClass(User.class).addClass(Post.class); SessionFactory sessions = cfg.buildSessionFactory(); new SchemaExport(cfg).create(true, true); Session session = sessions.openSession(); User user = new User("Gigix"); user.setMail("gigix@umlchina.com"); Post post = new Post(); post.setTitle("Test"); post.setContent("Only for Test"); user.getPosts().add(post); // getPosts()方法返回posts set session.save(user); session.flush(); session.close(); session = sessions.openSession(); Query q = session.createQuery("from Post as post where post.title = 'test'"); post = (Post) q.list().get(0); System.out.println(post.getOwner().getMail()); post.getOwner().setMail("xiongjie@csdn.net"); session.update(post); System.out.println(post.getOwner().getMail()); session.flush(); session.close(); } } //////////////////////////////////////////////// //////////////////////Post.java /* * Created on 2003-7-9 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package gigix.forum.bean; /** * @hibernate.class * table="POST" */ public class Post { private Long _id; private String _title; private String _content; private User _owner; public Post() { } /** * @hibernate.id * generator-class="identity" * column="POST_ID" */ public Long getId() { return _id; } private void setId(Long long1) { _id = long1; } /** * @hibernate.property * column="TITLE" */ public String getTitle() { return _title; } public void setTitle(String string) { _title = string; } /** * @hibernate.property * column="CONTENT" */ public String getContent() { return _content; } public void setContent(String string) { _content = string; } /** * @hibernate.many-to-one * column="OWNER_ID" */ public User getOwner() { return _owner; } private void setOwner(User user) { _owner = user; } public boolean equals(Object obj) { if(!(obj instanceof Post)) return false; return ((Post)obj).getId().equals(_id); } } ////////////////////////////////////////////// //////////////User.java /* * Created on 2003-7-6 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package gigix.forum.bean; import java.util.HashSet; import java.util.Set; /** * @hibernate.class * table="USER" */ public class User { private String _id; private String _mail; private String _password; private String _nick; private Set _posts; private User() {} public User(String id) { _id = id; _posts = new HashSet(); } /** * @hibernate.id * generator-class="assigned" * column="USER_ID" */ public String getId() { return _id; } private void setId(String id) { _id = id; } /** * @hibernate.property * column="E_MAIL" */ public String getMail() { return _mail; } public void setMail(String string) { _mail = string; } /** * @hibernate.property * column="PASSWORD" */ public String getPassword() { return _password; } public void setPassword(String string) { _password = string; } /** * @hibernate.property * column="NICK_NAME" */ public String getNick() { return _nick; } public void setNick(String string) { _nick = string; } /** * @hibernate.set * lazy="true" * order-by="POST_ID" * cascade="all" * @hibernate.collection-key * column="OWNER_ID" * @hibernate.collection-one-to-many * class="gigix.forum.bean.Post" */ public Set getPosts() { return _posts; } private void setPosts(Set set) { _posts = set; } public boolean equals(Object obj) { if(!(obj instanceof User)) return false; return ((User)obj).getId().equals(_id); } } |
|
返回顶楼 | |
发表时间:2003-11-21
UserHibernate中38行对应的是什么方法?
另外把show_sql设为true,重新贴出output。 |
|
返回顶楼 | |
发表时间:2003-11-21
还有你的User.hbm.xml也贴出来,应该是save(user)不对。
|
|
返回顶楼 | |
发表时间:2003-11-21
huili1725 写道 <set name="posts" lazy="true" inverse="false" cascade="all" sort="unsorted" order-by="POST_ID" > <one-to-many class="gigix.forum.bean.Post" /> </set> </class> </hibernate-mapping> 同学叫我打球,先去一下,回来再请教!!! 语焉不详。 把output输出来看看,记得把log4j.properties的log4j.logger.net.sf.hibernate.type=info改成debug。Hibernate的show_sql开关打开。 问题肯定是在你save(user)时级联保存了Post,而post有一个Long属性的字段放了一个字符。好好查查吧,应该不是很麻烦的。 |
|
返回顶楼 | |
发表时间:2003-11-22
//////output//////////////////
[root@huili src]# javac UserHibernate.java [root@huili src]# java UserHibernate 2003-10-25 16:19:27 net.sf.hibernate.cfg.Environment <clinit> 信息: Hibernate 2.1 beta 5 2003-10-25 16:19:27 net.sf.hibernate.cfg.Environment <clinit> 信息: loaded properties from resource hibernate.properties: {hibernate.connectio n.driver_class=com.mysql.jdbc.Driver, hibernate.cglib.use_reflection_optimizer=t rue, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, hibernate.jdbc.use _streams_for_binary=true, hibernate.jdbc.batch_size=0, hibernate.query.substitut ions=true 1, false 0, yes 'Y', no 'N', hibernate.connection.username=root, hiber nate.connection.url=jdbc:mysql://huili/hui, hibernate.connection.password=, hibe rnate.statement_cache.size=25, hibernate.connection.pool_size=1} 2003-10-25 16:19:27 net.sf.hibernate.cfg.Environment <clinit> 信息: using java.io streams to persist binary types 2003-10-25 16:19:27 net.sf.hibernate.cfg.Environment <clinit> 信息: using CGLIB reflection optimizer 2003-10-25 16:19:27 net.sf.hibernate.cfg.Configuration addClass 信息: Mapping resource: gigix/forum/bean/User.hbm.xml 2003-10-25 16:19:29 net.sf.hibernate.cfg.Binder bindRootClass 信息: Mapping class: gigix.forum.bean.User -> USER 2003-10-25 16:19:30 net.sf.hibernate.cfg.Configuration addClass 信息: Mapping resource: gigix/forum/bean/Post.hbm.xml 2003-10-25 16:19:30 net.sf.hibernate.cfg.Binder bindRootClass 信息: Mapping class: gigix.forum.bean.Post -> POST 2003-10-25 16:19:30 net.sf.hibernate.cfg.Configuration secondPassCompile 信息: processing one-to-many association mappings 2003-10-25 16:19:30 net.sf.hibernate.cfg.Binder bindCollectionSecondPass 信息: Mapping collection: gigix.forum.bean.User.posts -> POST 2003-10-25 16:19:30 net.sf.hibernate.cfg.Configuration secondPassCompile 信息: processing one-to-one association property references 2003-10-25 16:19:30 net.sf.hibernate.cfg.Configuration secondPassCompile 信息: processing foreign key constraints 2003-10-25 16:19:30 net.sf.hibernate.dialect.Dialect <init> 信息: Using dialect: net.sf.hibernate.dialect.MySQLDialect 2003-10-25 16:19:30 net.sf.hibernate.cfg.SettingsFactory buildSettings 信息: Use outer join fetching: true 2003-10-25 16:19:30 net.sf.hibernate.connection.DriverManagerConnectionProvider configure 信息: Using Hibernate built-in connection pool (not for production use!) 2003-10-25 16:19:30 net.sf.hibernate.connection.DriverManagerConnectionProvider configure 信息: Hibernate connection pool size: 1 2003-10-25 16:19:30 net.sf.hibernate.connection.DriverManagerConnectionProvider configure 信息: using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://huili/hui 2003-10-25 16:19:30 net.sf.hibernate.connection.DriverManagerConnectionProvider configure 信息: connection properties: {user=root, password=} 2003-10-25 16:19:30 net.sf.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup 信息: No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended) 2003-10-25 16:19:31 net.sf.hibernate.cfg.SettingsFactory buildSettings 信息: Use scrollable result sets: true 2003-10-25 16:19:31 net.sf.hibernate.cfg.SettingsFactory buildSettings 信息: Query language substitutions: {no='N', true=1, yes='Y', false=0} 2003-10-25 16:19:31 net.sf.hibernate.cfg.SettingsFactory buildSettings 信息: cache provider: net.sf.hibernate.cache.JCSCacheProvider 2003-10-25 16:19:31 net.sf.hibernate.cfg.Configuration configureCaches 信息: instantiating and configuring caches 2003-10-25 16:19:31 net.sf.hibernate.impl.SessionFactoryImpl <init> 信息: building session factory 2003-10-25 16:19:32 net.sf.hibernate.util.ReflectHelper getMetaClass 信息: reflection optimizer disabled for: gigix.forum.bean.Post, IllegalArgumentE xception: setOwner 2003-10-25 16:19:32 net.sf.hibernate.util.ReflectHelper getMetaClass 信息: reflection optimizer disabled for: gigix.forum.bean.User, IllegalArgumentE xception: setPosts 2003-10-25 16:19:32 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstanc e 信息: no JNDI name configured 2003-10-25 16:19:32 net.sf.hibernate.dialect.Dialect <init> 信息: Using dialect: net.sf.hibernate.dialect.MySQLDialect 2003-10-25 16:19:32 net.sf.hibernate.cfg.Configuration secondPassCompile 信息: processing one-to-many association mappings 2003-10-25 16:19:32 net.sf.hibernate.cfg.Configuration secondPassCompile 信息: processing one-to-one association property references 2003-10-25 16:19:32 net.sf.hibernate.cfg.Configuration secondPassCompile 信息: processing foreign key constraints 2003-10-25 16:19:32 net.sf.hibernate.cfg.Configuration secondPassCompile 信息: processing one-to-many association mappings 2003-10-25 16:19:32 net.sf.hibernate.cfg.Configuration secondPassCompile 信息: processing one-to-one association property references 2003-10-25 16:19:32 net.sf.hibernate.cfg.Configuration secondPassCompile 信息: processing foreign key constraints 2003-10-25 16:19:32 net.sf.hibernate.tool.hbm2ddl.SchemaExport execute 信息: Running hbm2ddl schema export 2003-10-25 16:19:32 net.sf.hibernate.tool.hbm2ddl.SchemaExport execute 信息: exporting generated schema to database 2003-10-25 16:19:32 net.sf.hibernate.connection.DriverManagerConnectionProvider configure 信息: Using Hibernate built-in connection pool (not for production use!) 2003-10-25 16:19:32 net.sf.hibernate.connection.DriverManagerConnectionProvider configure 信息: Hibernate connection pool size: 1 2003-10-25 16:19:32 net.sf.hibernate.connection.DriverManagerConnectionProvider configure 信息: using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://huili/hui 2003-10-25 16:19:32 net.sf.hibernate.connection.DriverManagerConnectionProvider configure 信息: connection properties: {user=root, password=} drop table if exists USER drop table if exists POST create table USER ( USER_ID VARCHAR(255) not null, E_MAIL VARCHAR(255), PASSWORD VARCHAR(255), NICK_NAME VARCHAR(255), primary key (USER_ID) ) create table POST ( POST_ID BIGINT NOT NULL AUTO_INCREMENT, TITLE VARCHAR(255), CONTENT VARCHAR(255), OWNER_ID VARCHAR(255), primary key (POST_ID) ) alter table POST add index (OWNER_ID), add constraint FK2590A091C80647 foreign k ey (OWNER_ID) references USER (USER_ID) 2003-10-25 16:19:33 net.sf.hibernate.tool.hbm2ddl.SchemaExport execute 信息: schema export complete 2003-10-25 16:19:33 net.sf.hibernate.connection.DriverManagerConnectionProvider close 信息: cleaning up connection pool: jdbc:mysql://huili/hui 2003-10-25 16:19:33 net.sf.hibernate.util.JDBCExceptionReporter logExceptions 警告: SQL Error: 0, SQLState: S1009 2003-10-25 16:19:33 net.sf.hibernate.util.JDBCExceptionReporter logExceptions 严重: Invalid value for getLong() - 'p' 2003-10-25 16:19:33 net.sf.hibernate.util.JDBCExceptionReporter logExceptions 警告: SQL Error: 0, SQLState: S1009 2003-10-25 16:19:33 net.sf.hibernate.util.JDBCExceptionReporter logExceptions 严重: Invalid value for getLong() - 'p' 2003-10-25 16:19:33 net.sf.hibernate.JDBCException <init> 严重: could not insert: [gigix.forum.bean.Post] java.sql.SQLException: Invalid value for getLong() - 'p' at com.mysql.jdbc.ResultSet.getLong(ResultSet.java:1420) at net.sf.hibernate.id.IdentifierGeneratorFactory.get(IdentifierGenerato rFactory.java:29) at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.jav a:574) at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.jav a:488) at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:803) at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:678) at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1324) at net.sf.hibernate.engine.Cascades$4.cascade(Cascades.java:113) at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:339) at net.sf.hibernate.engine.Cascades.cascadeCollection(Cascades.java:429) at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:355) at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:406) at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:385) at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:824) at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:678) at UserHibernate.main(UserHibernate.java:38) Exception in thread "main" net.sf.hibernate.JDBCException: could not insert: [gi gix.forum.bean.Post] at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.jav a:594) at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.jav a:488) at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:803) at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:678) at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1324) at net.sf.hibernate.engine.Cascades$4.cascade(Cascades.java:113) at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:339) at net.sf.hibernate.engine.Cascades.cascadeCollection(Cascades.java:429) at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:355) at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:406) at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:385) at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:824) at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:678) at UserHibernate.main(UserHibernate.java:38) Caused by: java.sql.SQLException: Invalid value for getLong() - 'p' at com.mysql.jdbc.ResultSet.getLong(ResultSet.java:1420) at net.sf.hibernate.id.IdentifierGeneratorFactory.get(IdentifierGenerato rFactory.java:29) at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.jav a:574) ... 13 more [root@huili src]# |
|
返回顶楼 | |
发表时间:2003-11-24
把
cascade="all" 改成 cascade="none" 试试。 另外你的Post的Id是long吗? |
|
返回顶楼 | |
发表时间:2003-11-24
对啊!没错啊!
|
|
返回顶楼 | |
发表时间:2003-11-24
如果cascade="none";
则post表不能加入数据。 cascade="all"的作用:删除user对象时,同时把user的所有post也删除。 |
|
返回顶楼 | |