These are problems we have encountered attampting to map a fairly complex model with a single root (Top). We have attempted several mappings. Without associations, union-subclass works. Unfortunately, this is union-subclass failing when mapping a many-to-many association using many-to-any using the intermediate table ProvisioningData.
Thanks for any help.
-steve
[b]Hibernate version: 3.0[/b]
[b]Mapping documents:[/b]
Fragments:
ServiceOrder takes both roles in the association which is being mapped. It is a subclass, ultimately of Top:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.cisco.nm.cto.tc.Top" abstract="true">
<id name="instanceId" type="long">
<generator class="sequence"/>
</id>
<set name="groupComponent_264" table="Component" inverse="true">
<key>
<column name="partComponent_264_ID"/>
</key>
<many-to-any id-type="long" meta-type="java.lang.String">
<meta-value value="16" class="com.cisco.nm.cto.aps.pep.DataLinkEndpoint"/>
<meta-value value="25" class="com.cisco.nm.cto.aps.pep.IPProtocolEndpoint"/>
<meta-value value="245" class="com.cisco.nm.cto.sys.ComputerSystem"/>
<meta-value value="223" class="com.cisco.nm.cto.so.ServiceOrder"/>
<meta-value value="52" class="com.cisco.nm.cto.assets.mac.PhysicalElement"/>
<meta-value value="93" class="com.cisco.nm.cto.assets.pesc.PhysicalMemory"/>
<meta-value value="87" class="com.cisco.nm.cto.assets.pesc.PhysicalConnector"/>
<meta-value value="195" class="com.cisco.nm.cto.sec.cred.SharedSecret"/>
<meta-value value="284" class="com.cisco.nm.cto.uao.OrgUnit"/>
<meta-value value="286" class="com.cisco.nm.cto.uao.Organization"/>
<meta-value value="299" class="com.cisco.nm.cto.uao.UserEntity"/>
<meta-value value="152" class="com.cisco.nm.cto.indications.AlertIndication"/>
<column name="groupComponent_264_Type"/>
<column name="groupComponent_264_Id" not-null="true"/>
</many-to-any>
</set>
<set name="partComponent_264" table="Component" inverse="false">
<key>
<column name="groupComponent_264_ID"/>
</key>
<many-to-any id-type="long" meta-type="java.lang.String">
<meta-value value="16" class="com.cisco.nm.cto.aps.pep.DataLinkEndpoint"/>
<meta-value value="25" class="com.cisco.nm.cto.aps.pep.IPProtocolEndpoint"/>
<meta-value value="245" class="com.cisco.nm.cto.sys.ComputerSystem"/>
<meta-value value="223" class="com.cisco.nm.cto.so.ServiceOrder"/>
<meta-value value="52" class="com.cisco.nm.cto.assets.mac.PhysicalElement"/>
<meta-value value="93" class="com.cisco.nm.cto.assets.pesc.PhysicalMemory"/>
<meta-value value="87" class="com.cisco.nm.cto.assets.pesc.PhysicalConnector"/>
<meta-value value="195" class="com.cisco.nm.cto.sec.cred.SharedSecret"/>
<meta-value value="284" class="com.cisco.nm.cto.uao.OrgUnit"/>
<meta-value value="286" class="com.cisco.nm.cto.uao.Organization"/>
<meta-value value="299" class="com.cisco.nm.cto.uao.UserEntity"/>
<meta-value value="152" class="com.cisco.nm.cto.indications.AlertIndication"/>
<column name="partComponent_264_Type"/>
<column name="partComponent_264_Id" not-null="true"/>
</many-to-any>
</set>
<set name="dependent_267" table="Dependency" inverse="true">
<key>
<column name="independent_267_ID"/>
</key>
<many-to-any id-type="long" meta-type="java.lang.String">
<meta-value value="16" class="com.cisco.nm.cto.aps.pep.DataLinkEndpoint"/>
<meta-value value="25" class="com.cisco.nm.cto.aps.pep.IPProtocolEndpoint"/>
<meta-value value="245" class="com.cisco.nm.cto.sys.ComputerSystem"/>
<meta-value value="223" class="com.cisco.nm.cto.so.ServiceOrder"/>
<meta-value value="52" class="com.cisco.nm.cto.assets.mac.PhysicalElement"/>
<meta-value value="93" class="com.cisco.nm.cto.assets.pesc.PhysicalMemory"/>
<meta-value value="87" class="com.cisco.nm.cto.assets.pesc.PhysicalConnector"/>
<meta-value value="195" class="com.cisco.nm.cto.sec.cred.SharedSecret"/>
<meta-value value="284" class="com.cisco.nm.cto.uao.OrgUnit"/>
<meta-value value="286" class="com.cisco.nm.cto.uao.Organization"/>
<meta-value value="299" class="com.cisco.nm.cto.uao.UserEntity"/>
<meta-value value="152" class="com.cisco.nm.cto.indications.AlertIndication"/>
<column name="dependent_267_Type"/>
<column name="dependent_267_Id" not-null="true"/>
</many-to-any>
</set>
<set name="independent_267" table="Dependency" inverse="false">
<key>
<column name="dependent_267_ID"/>
</key>
<many-to-any id-type="long" meta-type="java.lang.String">
<meta-value value="16" class="com.cisco.nm.cto.aps.pep.DataLinkEndpoint"/>
<meta-value value="25" class="com.cisco.nm.cto.aps.pep.IPProtocolEndpoint"/>
<meta-value value="245" class="com.cisco.nm.cto.sys.ComputerSystem"/>
<meta-value value="223" class="com.cisco.nm.cto.so.ServiceOrder"/>
<meta-value value="52" class="com.cisco.nm.cto.assets.mac.PhysicalElement"/>
<meta-value value="93" class="com.cisco.nm.cto.assets.pesc.PhysicalMemory"/>
<meta-value value="87" class="com.cisco.nm.cto.assets.pesc.PhysicalConnector"/>
<meta-value value="195" class="com.cisco.nm.cto.sec.cred.SharedSecret"/>
<meta-value value="284" class="com.cisco.nm.cto.uao.OrgUnit"/>
<meta-value value="286" class="com.cisco.nm.cto.uao.Organization"/>
<meta-value value="299" class="com.cisco.nm.cto.uao.UserEntity"/>
<meta-value value="152" class="com.cisco.nm.cto.indications.AlertIndication"/>
<column name="independent_267_Type"/>
<column name="independent_267_Id" not-null="true"/>
</many-to-any>
</set>
</class>
</hibernate-mapping>
Now, here is ServiceOrder:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<union-subclass name="com.cisco.nm.cto.so.ServiceOrder"
extends="com.cisco.nm.cto.logicalandEnabledLogicalElements.LogicalElement">
<component name="serviceActivity" class="com.cisco.nm.cto.so.OrderActivityKind">
<property name="ord" column="serviceActivity_ord"/>
<property name="name" column="serviceActivity_name"/>
</component>
<component name="lifecycleStatus" class="com.cisco.nm.cto.so.OrderStatusKind">
<property name="ord" column="lifecycleStatus_ord"/>
<property name="name" column="lifecycleStatus_name"/>
</component>
<property name="lifecycleDescription" column="lifecycleDescription"/>
<property name="orderType" column="orderType"/>
<property name="dateSubmitted" column="dateSubmitted"/>
<property name="requestedByDate" column="requestedByDate"/>
<property name="expedite" column="expedite"/>
<property name="dateCompleted" column="dateCompleted"/>
<set name="approvingEntity_210" table="ApprovalPath" inverse="false">
<key>
<column name="serviceOrder_210_ID"/>
</key>
<many-to-any id-type="long" meta-type="java.lang.String">
<meta-value value="284" class="com.cisco.nm.cto.uao.OrgUnit"/>
<meta-value value="286" class="com.cisco.nm.cto.uao.Organization"/>
<meta-value value="299" class="com.cisco.nm.cto.uao.UserEntity"/>
<column name="approvingEntity_210_Type"/>
<column name="approvingEntity_210_Id" not-null="true"/>
</many-to-any>
</set>
<any name="billedEntity_215" id-type="long" meta-type="java.lang.String">
<meta-value value="284" class="com.cisco.nm.cto.uao.OrgUnit"/>
<meta-value value="286" class="com.cisco.nm.cto.uao.Organization"/>
<meta-value value="299" class="com.cisco.nm.cto.uao.UserEntity"/>
<column name="billedEntity_215_Type"/>
<column name="billedEntity_215_Id"/>
</any>
<set name="provisioningElement_220" table="ProvisioningData" inverse="false">
<key>
<column name="serviceOrder_220_ID"/>
</key>
<many-to-any id-type="long" meta-type="java.lang.String">
<meta-value value="16" class="com.cisco.nm.cto.aps.pep.DataLinkEndpoint"/>
<meta-value value="25" class="com.cisco.nm.cto.aps.pep.IPProtocolEndpoint"/>
<meta-value value="245" class="com.cisco.nm.cto.sys.ComputerSystem"/>
<meta-value value="223" class="com.cisco.nm.cto.so.ServiceOrder"/>
<meta-value value="52" class="com.cisco.nm.cto.assets.mac.PhysicalElement"/>
<meta-value value="93" class="com.cisco.nm.cto.assets.pesc.PhysicalMemory"/>
<meta-value value="87" class="com.cisco.nm.cto.assets.pesc.PhysicalConnector"/>
<meta-value value="195" class="com.cisco.nm.cto.sec.cred.SharedSecret"/>
<meta-value value="284" class="com.cisco.nm.cto.uao.OrgUnit"/>
<meta-value value="286" class="com.cisco.nm.cto.uao.Organization"/>
<meta-value value="299" class="com.cisco.nm.cto.uao.UserEntity"/>
<column name="provisioningElement_220_Type"/>
<column name="provisioningElement_220_Id" not-null="true"/>
</many-to-any>
</set>
<one-to-one name="previousOrder_232" class="com.cisco.nm.cto.so.ServiceOrder"
property-ref="nextOrder_232"/>
<many-to-one name="nextOrder_232" class="com.cisco.nm.cto.so.ServiceOrder"
column="nextOrder_232" unique="true"/>
<any name="recipient_235" id-type="long" meta-type="java.lang.String">
<meta-value value="284" class="com.cisco.nm.cto.uao.OrgUnit"/>
<meta-value value="286" class="com.cisco.nm.cto.uao.Organization"/>
<meta-value value="299" class="com.cisco.nm.cto.uao.UserEntity"/>
<column name="recipient_235_Type"/>
<column name="recipient_235_Id"/>
</any>
<any name="requestor_238" id-type="long" meta-type="java.lang.String">
<meta-value value="284" class="com.cisco.nm.cto.uao.OrgUnit"/>
<meta-value value="286" class="com.cisco.nm.cto.uao.Organization"/>
<meta-value value="299" class="com.cisco.nm.cto.uao.UserEntity"/>
<column name="requestor_238_Type"/>
<column name="requestor_238_Id"/>
</any>
<set name="supplier_241" table="ServiceSupplier" inverse="false">
<key>
<column name="serviceOrder_241_ID"/>
</key>
<many-to-any id-type="long" meta-type="java.lang.String">
<meta-value value="284" class="com.cisco.nm.cto.uao.OrgUnit"/>
<meta-value value="286" class="com.cisco.nm.cto.uao.Organization"/>
<meta-value value="299" class="com.cisco.nm.cto.uao.UserEntity"/>
<column name="supplier_241_Type"/>
<column name="supplier_241_Id" not-null="true"/>
</many-to-any>
</set>
</union-subclass>
</hibernate-mapping>
[b]Code between sessionFactory.openSession() and session.close():
Some code has been deleted and replaced with ...
[code]public static void main(String[] args) {
s = HibernateUtil.currentSession();
populate(1);
...
HibernateUtil.closeSession();
}
protected static void populate(int count) {
Transaction tx = s.beginTransaction();
...
PhysicalConnector pc = new PhysicalConnector() ;
...
ServiceOrder so = new ServiceOrder() ;
...
so.getProvisioningElement_220().add(pc) ;
pc.getServiceOrder_220().add(so) ;
...
s.persist(pc);
s.persist(so);
...
tx.commit();
}
[/code]
[/b]
[b]Full stack trace of any exception that occurs:
08:52:51,358 ERROR AbstractFlushingEventListener:277 - Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:181)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at com.cisco.nm.cto.modeling.hibTest.HibTest.populate(HibTest.java:151)
at com.cisco.nm.cto.modeling.hibTest.HibTest.main(HibTest.java:40)
Caused by: java.sql.BatchUpdateException: ORA-00942: table or view does not exist
at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:4133)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:174)
... 7 more
Exception in thread "main" org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:181)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at com.cisco.nm.cto.modeling.hibTest.HibTest.populate(HibTest.java:151)
at com.cisco.nm.cto.modeling.hibTest.HibTest.main(HibTest.java:40)
Caused by: java.sql.BatchUpdateException: ORA-00942: table or view does not exist
at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:4133)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:174)
... 7 more
[/b]
[b]Name and version of the database you are using: Oracle 9[/b]
[b]The generated SQL (show_sql=true):
The definition of ProvisioningData:
09:06:02,324 DEBUG SchemaExport:161 - create table ProvisioningData (
provisioningElement_220_ID number(19,0) not null,
serviceOrder_220_ID number(19,0) not null,
provisioningElement_220_Type varchar2(255),
provisioningElement_220_Id number(19,0) not null,
primary key (serviceOrder_220_ID, provisioningElement_220_Id)
)
09:06:02,328 ERROR SchemaExport:167 - Unsuccessful: create table ProvisioningData (provisioningElement_220_ID number(19,0) not null, serviceOrder_220_ID number(19,0) not null, provisioningElement_220_Type varchar2(255), provisioningElement_220_Id number(19,0) not null, primary key (serviceOrder_220_ID, provisioningElement_220_Id))
09:06:02,329 ERROR SchemaExport:168 - ORA-00957: duplicate column name
And the insert which, of course, fails (since there is no table into which to insert):
insert into ProvisioningData (serviceOrder_220_ID, provisioningElement_220_Type, provisioningElement_220_Id) values (?, ?, ?)
09:06:06,025 WARN JDBCExceptionReporter:71 - SQL Error: 942, SQLState: 42000
09:06:06,026 ERROR JDBCExceptionReporter:72 - ORA-00942: table or view does not exist
09:06:06,030 WARN JDBCExceptionReporter:71 - SQL Error: 942, SQLState: 42000
09:06:06,031 ERROR JDBCExceptionReporter:72 - ORA-00942: table or view does not exist
[/b]
[b]Debug level Hibernate log excerpt:
...
09:21:20,708 INFO HbmBinder:1218 - Mapping collection: com.cisco.nm.cto.tc.ManagedElement.serviceOrder_220 -> ProvisioningData
...
09:21:20,708 INFO HbmBinder:1218 - Mapping collection: com.cisco.nm.cto.tc.ManagedElement.serviceOrder_220 -> ProvisioningData
...
09:21:29,338 DEBUG AbstractCollectionPersister:479 - Static SQL for collection: com.cisco.nm.cto.tc.ManagedElement.serviceOrder_220
09:21:29,339 DEBUG AbstractCollectionPersister:480 - Row insert: insert into ProvisioningData (provisioningElement_220_ID, serviceOrder_220_ID) values (?, ?)
09:21:29,339 DEBUG AbstractCollectionPersister:481 - Row update: update ProvisioningData set serviceOrder_220_ID=? where provisioningElement_220_ID=? and serviceOrder_220_ID=?
09:21:29,339 DEBUG AbstractCollectionPersister:482 - Row delete: delete from ProvisioningData where provisioningElement_220_ID=? and serviceOrder_220_ID=?
09:21:29,340 DEBUG AbstractCollectionPersister:483 - One-shot delete: delete from ProvisioningData where provisioningElement_220_ID=?
09:21:29,340 DEBUG AbstractCollectionPersister:479 - Static SQL for collection: com.cisco.nm.cto.uao.OrganizationalEntity.system_294
...
09:21:29,388 DEBUG AbstractCollectionPersister:480 - Row insert: insert into ProvisioningData (serviceOrder_220_ID, provisioningElement_220_Type, provisioningElement_220_Id) values (?, ?, ?)
09:21:29,388 DEBUG AbstractCollectionPersister:481 - Row update: update ProvisioningData set provisioningElement_220_Type=?, provisioningElement_220_Id=? where serviceOrder_220_ID=? and provisioningElement_220_Id=?
09:21:29,388 DEBUG AbstractCollectionPersister:482 - Row delete: delete from ProvisioningData where serviceOrder_220_ID=? and provisioningElement_220_Id=?
09:21:29,389 DEBUG AbstractCollectionPersister:483 - One-shot delete: delete from ProvisioningData where serviceOrder_220_ID=?
[/b]
[code][/code][code][/code][code][/code]
_________________ Stephen Schleimer
(408) 527-3291
Cisco Systems, Inc
|