Changing the attribute inverse from true to false does not solve the problem. The same exception is thrown.
Thanks in advance for any help
-Malu
Code:
<set name="orderItems" lazy="true" inverse="false"
cascade="save-update">
<key>
<column name="ORDER_BASKET_FK" />
</key>
<one-to-many
class="OrderItem" />
</set>
Hello everyone!
we have two tables in the database: an ORDER_ITEM and an ORDER_BASKET table. The ORDER_ITEM has a foreign key to the ORDER_BASKET table in order to realize a many-to-one relationship (many items to one basket).
We have these two tables mapped to the OrderItem and OrderBasket classes. The OrderItem class implements the interface IOrderItem. Analogously the OrderBasket class implements the IOrderBasket interface (see Mapping files below).
When an OrderBasket object is loaded, the corresponding OrderItems are loaded as well. But when an OrderItem is loaded the OrderItem.getOrderBasket() method does not return a proper OrderBasket object. Only the id attribute is loaded. And trying to read another attribute causes an org.hibernate.exception.GenericJDBCException to be thrown.
What causes the exception? And what is necessary to do to load the complete object?
Thanks in advance for any help
-Malu
Hibernate Version3.0, 3.1rc2
Mapping documents:OrderItem.hbm.xml<class name=OrderItem"
table="ORDER_ITEM">
<meta attribute="implements" inherit="false">
interfaces.IOrderItem
</meta>
<id name="id" type="java.lang.Long" olumn="SYS_GEN_KEY">
<generator class="sequence">
<param name="sequence">ORDER_ITEM_SEQ</param>
</generator>
</id>
<property name="uniqueId"
type=UniqueIdUserType"
column="SYS_GEN_KEY" not-null="true" unique="true" insert="false"
update="false">
<meta attribute="field-description">
Unique id (primary key)
</meta>
<meta attribute="use-in-tostring">true</meta>
</property>
<!--... OTHER PROPERTIES....-->
<!-- Associations -->
<!-- bi-directional many-to-one association to OrderBasket -->
<many-to-one name="orderBasket"
class="OrderBasket"
not-null="true">
<column name="ORDER_BASKET_FK" />
</many-to-one>
</class>
<!-- named queries -->
<query name="OrderItem.findByUniqueId">
<![CDATA[from OrderItem item where item.id = :id]]>
</query>
</hibernate-mapping>
OrderBasket.hbm.htm<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1
http://boss.bekk.no/boss/middlegen/ http://www.hibernate.org/ -->
<class name="OrderBasket"
table="ORDER_BASKET">
<meta attribute="implements" inherit="false">
IOrderBasket
</meta>
<id name="id" type="java.lang.Long" column="SYS_GEN_KEY">
<generator class="sequence">
<param name="sequence">ORDER_BASKET_SEQ</param>
</generator>
</id>
<property name="uniqueId"
type="UniqueIdUserType"
column="SYS_GEN_KEY" not-null="true" unique="true" insert="false"
update="false">
<meta attribute="field-description">
Unique id (primary key)
</meta>
<meta attribute="use-in-tostring">true</meta>
</property>
<!--OTHER PROPERTIES -->
<!-- Associations -->
<!-- bi-directional one-to-many association to OrderItem -->
<set name="orderItems" lazy="true" inverse="true"
cascade="save-update">
<key>
<column name="ORDER_BASKET_FK" />
</key>
<one-to-many
class="OrderItem" />
</set>
<!-- named queries -->
<query name="OrderBasket.findByUniqueId">
<![CDATA[from OrderBasket basket where basket.id = :id order by basket.orderDate desc]]>
</query>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():test code[b]
Code:
IOrderItem orderItemBo = orderItemDao.findByUniqueId(new UniqueId(1));
IOrderBasket orderBasket = orderItemBo.getOrderBasket();
assertNotNull(orderBasket);
orderItemBo.getCreationDate();
[b]order item DAO code[b]
Code:
public class OrderItemNativeDao extends HibernateDaoSupport implements IOrderItemNativeDao
{
/**
*
*/
public OrderItemNativeDao()
{
super();
}
public IOrderItem createEmptyBo()
{
return new OrderItem();
}
/* (non-Javadoc)
* @see IOrderItemNativeDao#findByUniqueId(IUniqueId)
*/
public IOrderItem findByUniqueId(IUniqueId orderItemUid) throws ObjectNotFoundException
{
Query query = getSession().getNamedQuery("OrderItem.findByUniqueId");
query.setString("id", orderItemUid.toString());
if (query.uniqueResult() != null)
{
return (IOrderItem) query.uniqueResult();
}
throw new ObjectNotFoundException("IOrderItem: Entity with [id=" + orderItemUid.toString() + "] not found");
}
}
[b]Full stack trace of any exception that occurs:org.hibernate.util.JDBCExceptionReporter.logExceptions (JDBCExceptionReporter.java:72) - Keine Daten gelesen
org.hibernate.exception.GenericJDBCException: could not load an entity: [OrderBasket#2222]
at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1359)
at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:116)
at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:101)
at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2471)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:351)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:332)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:113)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:75)
at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:643)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:59)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)
at OrderBasket$$EnhancerByCGLIB$$f2e2e08f.getCreationDate(<generated>)
at OrderItemDaoTest.testFindByUniqueId(OrderItemDaoTest.java:91)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60)
at java.lang.reflect.Method.invoke(Method.java:391)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:436)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:311)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.sql.SQLException: Keine Daten gelesen
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:162)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:227)
at oracle.jdbc.driver.OracleStatement.wasNullValue(OracleStatement.java:3052)
at oracle.jdbc.driver.OracleResultSetImpl.wasNull(OracleResultSetImpl.java:111)
at UniqueIdUserType.nullSafeGet(UniqueIdUserType.java:51)
at org.hibernate.type.CustomType.nullSafeGet(CustomType.java:100)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:80)
at org.hibernate.persister.entity.BasicEntityPersister.hydrate(BasicEntityPersister.java:1690)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:991)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:942)
at org.hibernate.loader.Loader.getRow(Loader.java:855)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:305)
at org.hibernate.loader.Loader.doQuery(Loader.java:412)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1345)
... 29 more
Name and version of the database you are using:Oracle 10.1g