-->
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.  [ 2 posts ] 
Author Message
 Post subject: using <one-to-one> with <any>
PostPosted: Thu May 27, 2004 12:13 pm 
Beginner
Beginner

Joined: Fri Oct 24, 2003 10:45 am
Posts: 22
Hi,

I would appreciate any advice regarding the foloowing issue.

I have two classes with the following mappings:

<class name="com.usaa.bank.clo.bom.financialstatement.FinancialItem" table="financial_item" lazy="false">
<id name="id" type="long" column="id">
<generator class="sequence">
<param name="sequence">financial_item_seq</param>
</generator>
</id>

<any name="product" access="field" meta-type="class" id-type="long" cascade="all">
<column name="product_class"/>
<column name="product_id"/>
</any>

</class>



<class name="com.usaa.bank.clo.bom.product.Product" table="product" lazy="true">
<id name="id" type="long" column="id">
<generator class="sequence">
<param name="sequence">product_seq</param>
</generator>
</id>

<one-to-one name="financialItem" class="com.usaa.bank.clo.bom.financialstatement.FinancialItem" outer-join="false" constrained="false" cascade="all" property-ref="product"/>

<joined-subclass>
...
</joined-subclass>
<joined-subclass>
...
</joined-subclass>
<joined-subclass>
...
</joined-subclass>
<joined-subclass>
...
</joined-subclass>

</class>


In FinancialItem class I had to use <any> mapping to avoid polymorphism problems when using lazy loading proxy (chapter 14.2 of hibernate doc)

But when I try to persist an instance of FinancialItem I am getting the following exception

net.sf.hibernate.MappingException: No persister for: java.lang.Long
at net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:344)
at net.sf.hibernate.impl.SessionImpl.getClassPersister(SessionImpl.java:2656)
at net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2663)
at net.sf.hibernate.impl.SessionImpl.getEntityIdentifierIfNotUnsaved(SessionImpl.java:2725)
at net.sf.hibernate.type.ObjectType.nullSafeSet(ObjectType.java:139)
at net.sf.hibernate.loader.Loader.bindPositionalParameters(Loader.java:674)
at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:713)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:185)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:831)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:851)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:57)
at net.sf.hibernate.loader.EntityLoader.loadByUniqueKey(EntityLoader.java:53)
at net.sf.hibernate.persister.AbstractEntityPersister.loadByUniqueKey(AbstractEntityPersister.java:1104)
at net.sf.hibernate.impl.SessionImpl.loadByUniqueKey(SessionImpl.java:3806)
at net.sf.hibernate.type.EntityType.resolveIdentifier(EntityType.java:218)
at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:2169)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:240)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:831)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:851)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:57)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:49)
at net.sf.hibernate.persister.NormalizedEntityPersister.load(NormalizedEntityPersister.java:405)
at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2081)
at net.sf.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:1899)
at net.sf.hibernate.proxy.LazyInitializer.initialize(LazyInitializer.java:53)
at net.sf.hibernate.proxy.LazyInitializer.initializeWrapExceptions(LazyInitializer.java:60)
at net.sf.hibernate.proxy.LazyInitializer.getImplementation(LazyInitializer.java:164)
at net.sf.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:108)
at com.usaa.bank.clo.bom.product.LoanProduct$$EnhancerByCGLIB$$39359c34.getRealClass(<generated>)
at com.usaa.bank.clo.bom.financialstatement.FinancialItem.getProduct(FinancialItem.java:630)
at com.usaa.bank.clo.bom.financialstatement.FinancialItemPersistenceTest.update(FinancialItemPersistenceTest.java:150)
at com.usaa.bank.clo.persistence.mgmt.PersistenceTest.testPersistence(PersistenceTest.java:185)
at java.lang.reflect.Method.invoke(Native Method)
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 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:329)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:218)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:151)


That does not happen if I don't use back reference (<one-to-one>) in Product class.

It looks like it is impossible to use <one-to-one> with property-ref when other side of bidirectional relationship is mapped with <any>

Any ideas?

thanks,
Andrey


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 21, 2005 10:30 am 
Beginner
Beginner

Joined: Fri Apr 09, 2004 12:47 pm
Posts: 36
I'm intersted me too. I'm using Hibernate 2.1.8 and I'm going to add exactly this type of mapping. I need the <any> mapping in one class, but I'd like to have an explicit back-reference, in order to have a foreing key in the database.


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

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.