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.  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: simple parent/child mapping question
PostPosted: Wed Jul 19, 2006 5:29 pm 
Newbie

Joined: Tue Sep 20, 2005 3:55 pm
Posts: 15
I'm trying to create a simple parent/child mapping where the parent has a generated id and I want the child's id to be automatically populated. This isn't happening with the below mappings. I'm saving with a cascade all on the parent object and the parent's id is generated. I read somewhere that a composite doesn't work with a generated id but this seems like a pretty common use-case. Can anyone see a problem with the below mappings? Thanks.


The parent's mapping is:

<class name="TCTransaction" ...

<id name="transactionId" column="trans_id">
<generator class="com.ms.pbcustody.transcapfx.model.TransactionIdGenerator" />
</id>

<set name="executions" inverse="true" cascade="all,delete-orphan">
<cache usage="read-write"/>
<key column="trans_id" not-null="true" />
<one-to-many class="com.ms.pbcustody.transcapfx.model.FXExecution" />
</set>


Child:

<class name="FXExecution" ...

<composite-id>
<key-property name="transactionId" column="trans_id"/>
</composite-id>

<many-to-one name="Transaction" column="trans_id" class="TCTransaction" fetch="join" update="false" insert="false" not-null="true" />


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 8:04 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
composite-ids cannot be automatically generated.

There's no need for a composite-id in that case, just use a normal id.

Remvoe inverse="true". That setting means that you cannot create a child by putting a transient element in the parent's collection. You must save the child first, then add it to the element. And as you don't want that, inverse="false" (the default) is what you need.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 10:39 pm 
Newbie

Joined: Tue Sep 20, 2005 3:55 pm
Posts: 15
I did try that before but I'm still getting an error with the change. I changed my parent mapping to "inverse=false":

Parent:
<id name="transactionId" column="trans_id">
<generator class="com.ms.pbcustody.transcapfx.model.TransactionIdGenerator" />
</id>

<set name="executions" inverse="false" cascade="all">
<cache usage="read-write"/>
<key column="trans_id" />
<one-to-many class="com.ms.pbcustody.transcapfx.model.FXExecution" />
</set>


Child:

<id name="transactionId" column="trans_id">
</id>

<many-to-one name="Transaction" column="trans_id" class="TCTransaction" update="false" insert="false" />

I removed the fetch="join" and not-null="true" attributes on the child. When I do a save on the parent, i'm getting this exception saying I have to set the ID manually. I don't want to set it manually, I want it to take from the parent. I thought that was the whole point of the parent/child, can you explain what you meant by "normal id"?


Exception raised - org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): com.ms.pbcustody.transcapfx.model.FXExecution
at org.hibernate.id.Assigned.generate(Assigned.java:33)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:91)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:98)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:502)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:494)
at org.hibernate.engine.CascadingAction$1.cascade(CascadingAction.java:134)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:213)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:157)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:290)
at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:185)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:160)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
at org.hibernate.engine.Cascade.cascade(Cascade.java:248)
at org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:410)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:299)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:167)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:114)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:98)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:502)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:494)
at org.hibernate.engine.CascadingAction$1.cascade(CascadingAction.java:134)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:213)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:157)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:290)
at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:185)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:160)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
at org.hibernate.engine.Cascade.cascade(Cascade.java:248)
at org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:410)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:299)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:167)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:114)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:98)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:502)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:494)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:490)
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:585)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
at $Proxy1.saveOrUpdate(Unknown Source)
at


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 10:45 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Normally for inverse="false" collections, you want not-null="true" in all <key> elements pointing to them.

Also, you have no generator for the id. Which means that you must manually assign the ID first. Which you don't want. Set the correct generator for transactionId.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 20, 2006 12:49 am 
Newbie

Joined: Tue Sep 20, 2005 3:55 pm
Posts: 15
tenwit wrote:
Normally for inverse="false" collections, you want not-null="true" in all <key> elements pointing to them.

Also, you have no generator for the id. Which means that you must manually assign the ID first. Which you don't want. Set the correct generator for transactionId.


So the question is if I set the ID generator to be the same user-implemented one I use in the parent, will hibernate automatically copy the ID from the parent to child instead of generating a new ID? I suspect it will generate a new ID which I do not want since it obtains a key from the DB.

When I set it to the same generator as in the parent, I get a mapping exception:

org.hibernate.MappingException: Repeated column in mapping for entity: com.ms.pbcustody.transcapfx.model.FXExecution column: trans_id (should be mapped with insert="false" update="false")

These are the complete mappings:

Parent:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.ms.pbcustody.transcapfx.model">
<class name="TCTransaction" table="TransCapture_beta..tc_transaction">
<cache usage="read-write"/>
<id name="transactionId" column="trans_id">
<generator class="com.ms.pbcustody.transcapfx.model.TransactionIdGenerator" />
</id>

<version name="storeTime" column="store_time" type="timestamp"/>
<property name="userId" column="user_id" not-null="true" />
<property name="transmissionId" column="transmission_id" not-null="true" />
<property name="transactionType" column="transaction_type" not-null="true" />
<property name="transactionStatus" column="transaction_status" not-null="true" />
<property name="processFlag" column="process_flag" not-null="true" />
<property name="authorizationTime" column="authorization_time" />
<property name="processingTime" column="processing_time" />
<property name="completionTime" column="completion_time" />
<property name="loginName" column="login_name" />
<property name="origTransId" column="orig_trans_id" />
<property name="referenceNo" column="reference_no" />
<property name="buClientId" column="bu_client_id" />
<property name="lastTransactionStatus" column="last_transaction_status" />
<property name="currentFlag" column="current_flag" not-null="true" optimistic-lock="false"/>
<property name="contentType" column="content_type" />
<property name="uuid" column="uuid" />

<set name="executions" inverse="false" cascade="all">
<cache usage="read-write"/>
<key column="trans_id" not-null="true"/>
<one-to-many class="com.ms.pbcustody.transcapfx.model.FXExecution" />
</set>

<many-to-one name="transmission" column="transmission_id" class="TCTransmission" fetch="join" update="false" insert="false" not-null="true" />
</class>
</hibernate-mapping>

Child:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.ms.pbcustody.transcapfx.model">
<class name="FXExecution" table="TransCapture_beta..fx_execution">

<cache usage="read-write"/>

<id name="transactionId" column="trans_id">
<generator class="com.ms.pbcustody.transcapfx.model.TransactionIdGenerator" />
</id>

<property name="seqNo" column="seq_no" unique="true" not-null="true"/>
<property name="recordType" column="record_type" />
<property name="transactionType" column="transaction_type" />
<property name="transactionLevel" column="transaction_level"/>
<property name="productType" column="product_type"/>
<property name="referenceNo" column="reference_no"/>
<property name="blockId" column="block_id"/>
<property name="executionAccountNo" column="exec_account_no"/>
<property name="accountNo" column="account_no"/>
<property name="executionBroker" column="exec_broker"/>
<property name="tradeDate" column="trade_date"/>
<property name="settlementDate" column="settlement_date"/>
<property name="buyCcy" column="buy_ccy"/>
<property name="sellCcy" column="sell_ccy"/>
<property name="buyQuantity" column="buy_quantity"/>
<property name="sellQuantity" column="sell_quantity"/>
<property name="fxRate" column="fx_rate"/>
<property name="clientBaseEquivalent" column="client_base_equivalent"/>
<property name="hedgeVsSpeculative" column="hedge_vs_speculative"/>
<property name="hearsayIndicator" column="hearsay_ind"/>
<property name="taxIndicator" column="tax_ind"/>
<property name="custodianBroker" column="custodian_broker"/>
<property name="moneyManager" column="money_manager"/>
<property name="bookId" column="book_id"/>
<property name="dealId" column="deal_id"/>
<property name="exchangeRate" column="exch_rate"/>
<property name="acquisationDate" column="acquisation_date"/>
<property name="comments" column="comments"/>
<property name="linkId" column="link_id"/>

<many-to-one name="Transaction" column="trans_id" class="TCTransaction" update="false" insert="false" />

</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 20, 2006 1:01 am 
Newbie

Joined: Tue Sep 20, 2005 3:55 pm
Posts: 15
When I remove the not-null="true" attribute in key tag in the parent's set mapping then the mapping exception goes away:

<set name="executions" inverse="false" cascade="all">
<cache usage="read-write"/>
<key column="trans_id" />
<one-to-many class="com.ms.pbcustody.transcapfx.model.FXExecution" />
</set>

But now it is generating 2 IDs, one for the parent, and one for the child.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 20, 2006 2:09 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
There's something wrong with your design then. You have a one-to-many, where the one side and the many side all have the same ID value? That's simply not possible. You cannot have two rows in the same table have the same ID, and if you have a one-to-many, the many side is going to have more than one row.

If there's only one execution per transaction, then you can use a one-to-one, and use the genereator="foreign" on the execution to copy the transaction's ID. If there's really more than one execution per transaction, then you need a different ID. It looks to me like the trans_id column in transaciton is not the ID, it's just the FK back to transaction.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 20, 2006 10:59 am 
Newbie

Joined: Tue Sep 20, 2005 3:55 pm
Posts: 15
tenwit wrote:
There's something wrong with your design then. You have a one-to-many, where the one side and the many side all have the same ID value? That's simply not possible. You cannot have two rows in the same table have the same ID, and if you have a one-to-many, the many side is going to have more than one row.

If there's only one execution per transaction, then you can use a one-to-one, and use the genereator="foreign" on the execution to copy the transaction's ID. If there's really more than one execution per transaction, then you need a different ID. It looks to me like the trans_id column in transaciton is not the ID, it's just the FK back to transaction.


The execution (child) table is joined with the parent on transactionID which is the ID. The execution table also has another key "SeqNo" which I defined as a normal property with not-null="true" and unique="true". So then for any transactionID, there would be multiple executions with an additional SeqNo. The SeqNo doesn't need to be in the relationship as it's only relevant to the child and doesn't add anything if I add it to the ID hence I left it out. I saw some other posts by members of the hibernate team saying it should be left out...anyway but that doesn't solve my problem.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 20, 2006 5:26 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
You have two options for implementing this:
  1. Use a list with a composite-element (see section 8.4 of the ref docs: most examples use sets, but the last example uses a list).
  2. Have your PK ad ID be the same (the transaction ID and seq No.) and stick with a simple set.
Given how many properties are in your child entity, I'd go with the second option just to keep the mapping more readable, but either option will work for you. However, you simply cannot have transaction id as the only ID column in the child class.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 20, 2006 6:59 pm 
Newbie

Joined: Tue Sep 20, 2005 3:55 pm
Posts: 15
tenwit wrote:
You have two options for implementing this:
  1. Use a list with a composite-element (see section 8.4 of the ref docs: most examples use sets, but the last example uses a list).
  2. Have your PK ad ID be the same (the transaction ID and seq No.) and stick with a simple set.
Given how many properties are in your child entity, I'd go with the second option just to keep the mapping more readable, but either option will work for you. However, you simply cannot have transaction id as the only ID column in the child class.


Can you elaborate or give an example of the 2nd option?

You said earlier the 1st option (composite) will not work with a generated ID, correct? If that is the case, then how is everyone else mapping this kind of relationship which is the most common use-case. I don't think it makes sense to assign an ID manually for every child as it destroys the point of using a cascade-all in that case.

I can get it to work with kind of a hack right now by generating two users IDs and then placing a check on the child object if its parent has an ID but I know there must be a better way to do this. From a design perspective, I don't see why hibernate would have any limitation in copying IDs.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 21, 2006 12:09 pm 
Newbie

Joined: Tue Sep 20, 2005 3:55 pm
Posts: 15
BTW I did get the correct behaviour where parents generates ID and automatically assigns it to the child using the below:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.ms.pbcustody.transcapfx.model">
   <class name="TCTransaction" table="TransCapture_beta..tc_transaction">
      <cache usage="read-write"/>
      <id name="transactionId" column="trans_id">
         <generator class="com.ms.pbcustody.transcapfx.model.TransactionIdGenerator" />
      </id>
      <version name="storeTime" column="store_time" type="timestamp"/>
      <property name="userId" column="user_id" not-null="true" />
      <property name="transmissionId" column="transmission_id" not-null="true" />
      <property name="transactionType" column="transaction_type" not-null="true" />
      <property name="transactionStatus" column="transaction_status" not-null="true" />
      <property name="processFlag" column="process_flag" not-null="true" />
      <property name="authorizationTime" column="authorization_time" />
      <property name="processingTime" column="processing_time" />
      <property name="completionTime" column="completion_time" />
      <property name="loginName" column="login_name" />
      <property name="origTransId" column="orig_trans_id" />
      <property name="referenceNo" column="reference_no" />
      <property name="buClientId" column="bu_client_id" />
      <property name="lastTransactionStatus" column="last_transaction_status" />
      <property name="currentFlag" column="current_flag" not-null="true" optimistic-lock="false"/>
      <property name="contentType" column="content_type" />
      <property name="uuid" column="uuid" />

      <set name="executions" inverse="true" cascade="all">
         <cache usage="read-write"/>
         <key column="trans_id" />
         <one-to-many class="com.ms.pbcustody.transcapfx.model.FXExecution" />
      </set>
      <set name="allocations" inverse="true" cascade="all">
         <cache usage="read-write"/>
         <key column="trans_id" />
         <one-to-many class="com.ms.pbcustody.transcapfx.model.FXAllocation" />
      </set>
      <many-to-one name="transmission" column="transmission_id" class="TCTransmission" fetch="join" update="false" insert="false" not-null="true" />
   </class>
</hibernate-mapping>



Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.ms.pbcustody.transcapfx.model">
   <class name="FXExecution" table="TransCapture_beta..fx_execution">

      <cache usage="read-write" />

      <composite-id>
         <key-many-to-one name="Transaction" class="com.ms.pbcustody.transcapfx.model.TCTransaction">
            <column name="trans_id" not-null="true"/>
         </key-many-to-one>
         <key-property name="seqNo" column="seq_no"  />
      </composite-id>

      <version name="updateTime" column="update_time" type="timestamp" />

      <property name="recordType" column="record_type" />
      <property name="transactionType" column="transaction_type" />
      <property name="transactionLevel" column="transaction_level" />
      <property name="productType" column="product_type" />
      <property name="referenceNo" column="reference_no" />
      <property name="blockId" column="block_id" />
      <property name="executionAccountNo" column="exec_account_no" />
      <property name="accountNo" column="account_no" />
      <property name="executionBroker" column="exec_broker" />
      <property name="tradeDate" column="trade_date" />
      <property name="settlementDate" column="settlement_date" />
      <property name="buyCcy" column="buy_ccy" />
      <property name="sellCcy" column="sell_ccy" />
      <property name="buyQuantity" column="buy_quantity" />
      <property name="sellQuantity" column="sell_quantity" />
      <property name="fxRate" column="fx_rate" />
      <property name="clientBaseEquivalent" column="client_base_equivalent" />
      <property name="hedgeVsSpeculative" column="hedge_vs_speculative" />
      <property name="hearsayIndicator" column="hearsay_ind" />
      <property name="taxIndicator" column="tax_ind" />
      <property name="custodianBroker" column="custodian_broker" />
      <property name="moneyManager" column="money_manager" />
      <property name="bookId" column="book_id" />
      <property name="dealId" column="deal_id" />
      <property name="exchangeRate" column="exch_rate" />
      <property name="acquisationDate" column="acquisation_date" />
      <property name="comments" column="comments" />
      <property name="linkId" column="link_id" />

      <many-to-one name="Transaction" column="trans_id" class="TCTransaction" not-null="true" update="false" insert="false"/>
   </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 23, 2006 5:49 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
That is the option 2 solution as I envisaged it. The PK and ID are the same (trans_id + seqNo), and you've gone with two separate mappings. That's what I'd have done.

If seqNo is a simple sequence, and each trans_id has its own sequence, then you could also move seqNo to the index of a list, which would make things even more compact and self-managing.

BTW I think you want inverse="false" on that set. FXExecutions are completely dependent on TCTransactions: you cannot create an execution except in the Executions set of a transaction. Therefore, inverse="false".

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject: SeqNo as sequence
PostPosted: Mon Dec 11, 2006 2:36 pm 
Newbie

Joined: Mon Dec 11, 2006 2:11 pm
Posts: 2
Hello and excuse my english, please.

If a sequence is not posible to used in a composite-id, what can i do to define the key SeqNo as sequence or as auto-generate key throught a trigger?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 11, 2006 4:19 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Is a <list> appropriate? Hibernate lists effectively add a sequence number to an "ordinary" collection.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 12, 2006 9:47 am 
Newbie

Joined: Mon Dec 11, 2006 2:11 pm
Posts: 2
It's posible that list will be appropiate, but i have to work with a DB squema that i don't change (other applic. access to this DB).

So, all "id's" (an id and an id+count) in the tables are auto-generated throught triggers.

For example,
I have "Master" and "Detail" tables:
Code:
create table Master (
  id bigint not null primary key)

create table Detail (
  idMaster bigint not null primary key,
  count bigint not null primary key)

alter table Detail add constraint detail_master_fk (idMaster) references Master (id)


hibernate mapping:
Code:
<class name="Master" table="Master" class="Master">
<id name="id_master" type="integer" >
  <generator class="select" >
   <param name="key">ID</param>
  </generator>
</id>

<set name="details" cascade="save-update" lazy="true">
  <key column="idMaster"/>
  <one-to-many class="Detail"/>
</set>
</class>

<class name="Detail" table="Detail" class="Detail">
<composite-id>
  <key-many-to-one name="detail" class="Detail">
   <column name="count" not-null="true"/>
  </key-many-to-one>
  <key-property name="count" column="count"  />
</composite-id>
</class>



What can i do for mapping this "count" as PK auto-generated?

Thanks


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

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.