-->
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: property-ref using a component
PostPosted: Wed May 10, 2006 10:07 am 
Newbie

Joined: Thu Mar 23, 2006 6:52 pm
Posts: 5
Location: Calgary
Here's what I'm trying to do. I have a security overview which has a surrogate primary key. It also has three columns which I map into a component (ContractHeaderId). The Security Table also has these three columns (and the mapped object is a component as well). Can I use the component as a property with the <Key property-ref="contractHeaderId">?

If not, how would you map this relationship?


Hibernate version:
3.1.1.

Mapping documents:

Security Overview
<?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 default-lazy="false">
<class name="org.transalta.creditservices.model.implementation.ContractSecurityOverview" table="CPTY_CONTRACTS">

<id name="counterpartyContractId" column="CPTY_CONTRACT_ID">
<generator class="assigned" />
</id>
<component name="contractHeaderId" class="org.transalta.creditservices.model.implementation.ContractHeaderId" >
<property name="counterPartyId" column="CPTY_ORGANIZATION_ID" not-null="true"/>
<property name="transAltaLegalEntityId" column="TA_ORGANIZATION_ID" not-null="true"/>
<property name="masterEnablingContractCode" column="MASTER_ENABLING_CONTRACT_CODE" not-null="true"/>
</component>
<!--<bag name="issuedSuretyBonds" lazy="false" fetch="join">
<key update="false">
<column name="CPTY_ORGANIZATION_ID"/>
<column name="TA_ORGANIZATION_ID"/>
<column name="MASTER_ENABLING_CONTRACT_CODE"/>
</key>
<one-to-many class="org.transalta.creditservices.model.implementation.IssuedSuretyBond" />

</bag>
</class>
</hibernate-mapping>


Security
<?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="org.transalta.creditservices.model.implementation.SecurityImpl" table="SECURITIES">
<id name="securityId" column="SECURITY_ID" >
<generator class="sequence">
<param name="sequence">SECURITIES_SEQ</param>
</generator>
</id>
<discriminator type="string"
formula="case
when SECURITY_TYPE_CODE='LOC' and ISSUED_RECEIVED = 'I' then 'ISSUED_LETTEROFCREDIT'
when SECURITY_TYPE_CODE='LOC' and ISSUED_RECEIVED = 'R' then 'HELD_LETTEROFCREDIT'
when SECURITY_TYPE_CODE='CASH' and ISSUED_RECEIVED = 'I' then 'ISSUED_CASH'
when SECURITY_TYPE_CODE='CASH' and ISSUED_RECEIVED = 'R' then 'HELD_CASH'
when SECURITY_TYPE_CODE='SURETY' and ISSUED_RECEIVED = 'I' then 'ISSUED_SURETY'
when SECURITY_TYPE_CODE='SURETY' and ISSUED_RECEIVED = 'R' then 'HELD_SURETY'
when SECURITY_TYPE_CODE='GUARANTEE' and ISSUED_RECEIVED = 'I' then 'ISSUED_GUARANTEE'
when SECURITY_TYPE_CODE='GUARANTEE' and ISSUED_RECEIVED = 'R' then 'HELD_GUARANTEE'
else SECURITY_TYPE_CODE end" force="true" />

<component name="contractId" class="org.transalta.creditservices.model.implementation.ContractHeaderId" >
<property name="counterPartyId" column="CPTY_ORGANIZATION_ID" />
<property name="transAltaLegalEntityId" column="TA_ORGANIZATION_ID" />
<property name="masterEnablingContractCode" column="MASTER_ENABLING_CONTRACT_CODE" />
</component>

<component name="amount" class="com.durablemethods.utils.Money"> <!-- class attribute optional -->
<property name="amount" column="SECURITY_AMOUNT"/>
<property name="currencyCode" column="CURRENCY_CODE"/>
</component>




<property name="startDate" column="START_DATE" />
<property name="endDate" column="END_DATE" />
<property name="issuedReceived" column="ISSUED_RECEIVED" />
<property name="transAltaContact" column="CONTACT_INFORMATION" />
<property name="typeCode" column="SECURITY_TYPE_CODE" />
<property name="createUserId" column="CREATE_USERID" />
<property name="updateUserId" column="UPDATE_USERID" />
<property name="createTimestamp" column="CREATE_TIMESTAMP" />
<property name="updateTimestamp" column="UPDATE_TIMESTAMP" />

<subclass name="org.transalta.creditservices.model.implementation.IssuedCash" discriminator-value="ISSUED_CASH" />
<subclass name="org.transalta.creditservices.model.implementation.IssuedSuretyBond" discriminator-value="ISSUED_SURETY" />
<subclass name="org.transalta.creditservices.model.implementation.IssuedGuarantee" discriminator-value="ISSUED_GUARANTEE" />
<subclass name="org.transalta.creditservices.model.implementation.IssuedLetterOfCredit" discriminator-value="ISSUED_LETTEROFCREDIT" />
<subclass name="org.transalta.creditservices.model.implementation.HeldCash" discriminator-value="HELD_CASH" />
<subclass name="org.transalta.creditservices.model.implementation.HeldSuretyBond" discriminator-value="HELD_SURETY" />
<subclass name="org.transalta.creditservices.model.implementation.HeldGuarantee" discriminator-value="HELD_GUARANTEE" />
<subclass name="org.transalta.creditservices.model.implementation.HeldLetterOfCredit" discriminator-value="HELD_LETTEROFCREDIT" />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:
ERROR - Fatal exception:Logging in to database failed:org.hibernate.MappingException::collection foreign key mapping has wrong number of columns: org.transalta.creditservices.model.implementation.ContractSecurityOverview.issuedLettersOfCredit type: component[counterPartyId,transAltaLegalEntityId,masterEnablingContractCode]
java.lang.RuntimeException: Logging in to database failed:org.hibernate.MappingException::collection foreign key mapping has wrong number of columns: org.transalta.creditservices.model.implementation.ContractSecurityOverview.issuedLettersOfCredit type: component[counterPartyId,transAltaLegalEntityId,masterEnablingContractCode]
at com.durablemethods.persistence.DataSessionFactory.login(DataSessionFactory.java:52)
at com.durablemethods.persistence.DataSessionFactory.<init>(DataSessionFactory.java:35)
at com.durablemethods.persistence.DataSessionFactory.<clinit>(DataSessionFactory.java:26)
at org.transalta.creditservices.services.SecurityServices.saveSecurity(SecurityServices.java:42)
at org.transalta.creditservices.servicetests.SecurityServicesTests.testSaveSecuritySuccessfully(SecurityServicesTests.java:102)
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)


Name and version of the database you are using:
Oracle 10

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

[size=9]
[/size][/size]


Top
 Profile  
 
 Post subject: Re: property-ref using a component
PostPosted: Thu May 11, 2006 5:50 pm 
Newbie

Joined: Thu Mar 23, 2006 6:52 pm
Posts: 5
Location: Calgary
Ahh yes....<properties>

sorry folks, should have kept reading.


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.