求助,java.sql.SQLException:流已被关闭

songjia1741 2011-03-20 11:03:42
自己做的一个小的模拟邮件的项目, 在Mysql中正常完成并通过。。。。
当迁移到ORACLE上的时候发生错误,

有两个类UserService合MailService, 继承于同一父类DaoSupport

调用同一个父类方法:就是这个方法出的错


@SuppressWarnings("unchecked")
@Transactional(readOnly=true, propagation=Propagation.NOT_SUPPORTED)
public <T> T find(Class<T> entityClass, Object entityId) {
return (T)hibernateTemplate.get(entityClass, (Serializable) entityId);
}


UserService可以正常执行, 但是MailService报错。。

控制台:

信息: Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
2011-3-20 8:49:24 org.springframework.jdbc.support.SQLErrorCodesFactory <init>
信息: SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]



经过JUNIT测试 报错


org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: could not load an entity: [com.song.mail.model.mail.MailInfo#1]; uncategorized SQLException for SQL

[select mailinfo0_.mailInfoId as mailInfoId1_2_, mailinfo0_.cont as cont1_2_, mailinfo0_.createDate as createDate1_2_, mailinfo0_.sendUser as sendUser1_2_, mailinfo0_.title as

title1_2_, mailinfo0_.unread as unread1_2_, mailinfo0_.userId as userId1_2_, user1_.userId as userId0_0_, user1_.password as password0_0_, user1_.userName as userName0_0_,

user2_.userId as userId0_1_, user2_.password as password0_1_, user2_.userName as userName0_1_ from MailInfo mailinfo0_ left outer join mailUser user1_ on

mailinfo0_.sendUser=user1_.userId left outer join mailUser user2_ on mailinfo0_.userId=user2_.userId where mailinfo0_.mailInfoId=?]; SQL state [null]; error code [17027]; 流已被

关闭; nested exception is java.sql.SQLException: 流已被关闭
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.orm.hibernate3.HibernateAccessor.convertJdbcAccessException(HibernateAccessor.java:424)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:410)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:525)
at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:519)
at com.song.mail.dao.DaoSupport.find(DaoSupport.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy16.find(Unknown Source)
at com.song.mail.service.mail.TestMailService.testMailServiceFind(TestMailService.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.sql.SQLException: 流已被关闭
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:111)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:207)
at oracle.jdbc.driver.LongAccessor.getBytes(LongAccessor.java:150)
at oracle.jdbc.driver.LongAccessor.getString(LongAccessor.java:192)
at oracle.jdbc.driver.T4CLongAccessor.getString(T4CLongAccessor.java:421)
at oracle.jdbc.driver.OracleResultSetImpl.getString(OracleResultSetImpl.java:396)
at oracle.jdbc.driver.OracleResultSet.getString(OracleResultSet.java:1514)
at org.apache.commons.dbcp.DelegatingResultSet.getString(DelegatingResultSet.java:225)
at org.hibernate.type.StringType.get(StringType.java:41)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:184)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:173)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:105)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2114)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1404)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1332)
at org.hibernate.loader.Loader.getRow(Loader.java:1230)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:603)
at org.hibernate.loader.Loader.doQuery(Loader.java:724)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1885)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:71)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:65)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3062)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:434)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:415)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:165)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:223)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:126)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:906)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:843)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:836)
at org.springframework.orm.hibernate3.HibernateTemplate$1.doInHibernate(HibernateTemplate.java:531)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
... 40 more

...全文
440 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
songjia1741 2011-03-20
有两个实体类 User 和 MailInfo


/**用户实体类**/
@Entity
@Table(name="mailUser")
public class User implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;

private int userId;
private String userName;
private String password;

@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="MAILUSER_SEQ")
@SequenceGenerator(name="MAILUSER_SEQ",allocationSize=1,initialValue=1, sequenceName="MAILUSER_SEQ")
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}

@Column(nullable=false, length=100, unique=true)
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}

@Column(nullable=false, length=20)
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}


/**邮件信息实体类**/
@Entity
public class MailInfo implements Serializable{

private static final long serialVersionUID = 1L;

/**编号**/
private int mailInfoId;
/**标题**/
private String title;
/**内容**/
private String cont;
/**创建时间**/
private Date createDate;
/**是否是未读邮件**/
private boolean isUnread = false;
/**收件人**/
private User userId;
/**发件人**/
private User sendUser;

@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="MAILINFO_SEQ")
@SequenceGenerator(name="MAILINFO_SEQ",allocationSize=1,initialValue=1, sequenceName="MAILINFO_SEQ")
public int getMailInfoId() {
return mailInfoId;
}
public void setMailInfoId(int mailInfoId) {
this.mailInfoId = mailInfoId;
}
@Column(length=100, nullable=false)
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@Column(length=8000, nullable=false)
public String getCont() {
return cont;
}
public void setCont(String cont) {
this.cont = cont;
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public boolean isUnread() {
return isUnread;
}
public void setUnread(boolean isUnread) {
this.isUnread = isUnread;
}

@ManyToOne
@JoinColumn(name="userId")
public User getUserId() {
return userId;
}
public void setUserId(User userId) {
this.userId = userId;
}
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="sendUser")
public User getSendUser() {
return sendUser;
}
public void setSendUser(User sendUser) {
this.sendUser = sendUser;
}
}

回复
songjia1741 2011-03-20
找到原因了

这种错误基本是由于hibernte自动创建表时,在oracle中字段为long的原因所致,修改long为Clob即可。
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2011-03-20 11:03
社区公告
暂无公告