-->
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: Trouble with multiple inheritance
PostPosted: Tue May 08, 2007 11:54 am 
Newbie

Joined: Tue May 08, 2007 11:28 am
Posts: 10
Explanation of answers below
Billable is an interface which is implemented by Advertiser and AffiliateUser. We do this so when we bill a user, we can use the interface instead of having to write extra code for both classes. The problem is that the concrete instance of this class is already mapped elsewhere, so I am getting this DuplicateMappingException. I looked at some other posts here and they implied that explicit would work but it doesn't. Billiable is really being used as a view to an existing class. So the code would be something like:

Code:
public class Bill {
   public void setBillable(Billable b) {... normal setter implementation ...}
}

//=========

public class BillingService {
   public void payBill(Bill bill) {
        BillingProfile profile = bill.getBillable().getProfile();
        cardService.payBill(profile.getCreditCard(), bill);
   }
}




I guess the question is, if this is not the right way to accomplish this, A) is it possible, and B) how should I do it differently?

Hibernate version:
3.1

Mapping documents:
Code:
  <class name="Billable" polymorphism="explicit">
     <cache usage="read-only" />
     <id name="uid" column="uid" type="string" />
     <one-to-one name="billingProfile" class="com.pkg.BillingProfile"></one-to-one>

    <union-subclass name="com.pkg.Advertiser"  table="advertiser" />

    <union-subclass name="com.pkg.AffiliateUser" table="affiliate_user" />
  </class>


Code between sessionFactory.openSession() and session.close():
Doesn't get that far.

Full stack trace of any exception that occurs:
Code:
org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/pkg/Billable.hbm.xml
   at org.hibernate.cfg.Configuration.addResource(Configuration.java:569)
   at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1587)
   at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)
   at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
   at com.pkg.util.hibernate.AccountHibernateUtil.<clinit>(AccountHibernateUtil.java:59)
   at com.pkg.domain.test.PersistenceTest.writeAdvertiser(PersistenceTest.java:45)
   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.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
   at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
   at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
   at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
   at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
   at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:71)
   at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
   at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
   at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
   at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
   at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
   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: org.hibernate.DuplicateMappingException: Duplicate table mapping advertiser
   at org.hibernate.cfg.Mappings.addDenormalizedTable(Mappings.java:192)
   at org.hibernate.cfg.HbmBinder.bindUnionSubclass(HbmBinder.java:787)
   at org.hibernate.cfg.HbmBinder.handleUnionSubclass(HbmBinder.java:2194)
   at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2107)
   at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2031)
   at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:359)
   at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:273)
   at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:144)
   at org.hibernate.cfg.Configuration.add(Configuration.java:669)
   at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:504)
   at org.hibernate.cfg.Configuration.addResource(Configuration.java:566)
   ... 27 more


Name and version of the database you are using:
mysql 5.0.24

The generated SQL (show_sql=true):
None

Debug level Hibernate log excerpt:
Doesn't get that far.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 09, 2007 11:04 am 
Newbie

Joined: Tue May 08, 2007 11:28 am
Posts: 10
So I think I may have resolved this, but I don't think I like the outcome.

Basically, what I am seeing is that I have to use the table-per-concrete-class with implicit polymorphism, can anyone verify that?


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.