-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate java.sql.SQLException after Oracle Schema change.
PostPosted: Fri Jun 20, 2014 8:48 pm 
Newbie

Joined: Fri Jun 20, 2014 8:34 pm
Posts: 1
I have a relationship which is somethign similar to the model mentioned below:
public class Parent {
private Long parentId;
private List<Child> children;

@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL)
@OrderBy("childNumber asc")
public List<Child> getChildren() {
return children;
}

@Id
@SequenceGenerator(name = "SOME_ID_GENERATOR", sequenceName = "SOME_ID_SEQ")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SOME_ID_GENERATOR")
@Column(name = PARENT_ID, nullable = false)
public Long getParentId() {
return parentId;
}
}

public class Child {
private Long childId;
private Parent parent;
private long childNumber;

@Id
@SequenceGenerator(name = "SOME_GENERATOR", sequenceName = "SOME_SEQ")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SOME_GENERATOR")
@Column(name = "CHILD_ID")
public Long getChildId() {
return childId;
}
public void setChildId(Long childId) {
this.childId = childId;
}

@ManyToOne
@JoinColumn(name = "PARENT_ID")
public Parent getParent() {
return parent;
}
public void setParent(Parent parent) {
this.parent = parent;
}

@Column(name = "CHILD_NUMBER", nullable = false)
public long getChildNumber() {
return childNumber;
}
public void setChildNumber(long childNumber) {
this.childNumber = childNumber;
}
}

Now as you can see the child id is a Long in the Hibernate model. But due to a human error the Oracle database datatype for that field was set to a varchar. The DBA noticed this problem and then decided to change the schema and make it a number instead of a varchar. When this was done all our requests immediately started failing with this exception:

org.hibernate.exception.GenericJDBCException: could not initialize a collection: [Parent.children#56065]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.loadCollection(Loader.java:2173)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:62)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:627)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:83)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1863)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:369)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:111)
at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:134)
at org.hibernate.collection.PersistentBag.size(PersistentBag.java:248)
application stack trace
at org.springframework.internal.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
application stack trace
Caused by: java.sql.SQLException: Fail to convert to internal representation
at oracle.jdbc.driver.CharCommonAccessor.getLong(CharCommonAccessor.java:297)
at oracle.jdbc.driver.T4CVarcharAccessor.getLong(T4CVarcharAccessor.java:862)
at oracle.jdbc.driver.OracleResultSetImpl.getLong(OracleResultSetImpl.java:985)
at oracle.jdbc.driver.OracleResultSet.getLong(OracleResultSet.java:440)
at com.mchange.v2.c3p0.impl.NewProxyResultSet.getLong(NewProxyResultSet.java:2625)
at org.hibernate.type.descriptor.sql.BigIntTypeDescriptor$2.doExtract(BigIntTypeDescriptor.java:61)
at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:64)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:254)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:250)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:230)
at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:331)
at org.hibernate.loader.Loader.extractKeysFromResultSet(Loader.java:668)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:606)
at org.hibernate.loader.Loader.doQuery(Loader.java:829)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
at org.hibernate.loader.Loader.loadCollection(Loader.java:2166)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:62)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:627)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:83)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1863)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:369)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:111)
at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:134)
at org.hibernate.collection.PersistentBag.size(PersistentBag.java:248)


Since the hibernate datatype was long we are wondering why hibernate threw this exception when the data type was changed to number. The DBA immediately reverted it back and then it went away. Does anyone have any similar experience? Or does someone know if hibernate caches the table schema somewhere and that caused a problem?

Any help would be appreciated.

Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.