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.