Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 341
  • Last Modified:

same attribute in two or more "one to many" relations in hibernate

I have a database schema that I want to use it in a client and also in a web server. All the clients are related to just one office so all the tables have an id that is unique in client side.  But when they are transformed to the server, their ids won't be unique and they need some additional field in their primary key  to be still unique. For this purpose I added an Office entity to my schema that actually make records unique in the server side. so some of the tables has office_id to be used in their primary key(as a composite primary key in addition to their id). But some of these tables(the tables with composite pks) has many to one relations to each other.
But it doesn't work properly.
For example:
<composite-id name = "id" class="A" >
            <key-property name="officeId" type="integer">
                  <column name="office_id" not-null="true" />
            </key-property>
            <key-property name="customerId" type="integer">
                <column name="customer_id" not-null="true" />
            </key-property>
        </composite-id>  
               
        <many-to-one name="account" class="B" fetch="select" lazy="false" cascade="save-update,persist"  insert="false" update="false">
            <column name="office_id" not-null="true" />
            <column name="account_id" not-null="true" />
        </many-to-one>

when I set insert="false" then the query made by hibernate doesn't contain account_id and account_id is not nullable so it gives me an error. If I delete insert="false" and update="false", hibernate doesn't start and dies.

One solution is to put the account_id in the composite_id too. But it's inconvenient.
Does anybody has another solution for this situation to work?
0
amirmb
Asked:
amirmb
  • 3
1 Solution
 
Amitkumar PSr. ConsultantCommented:
Please share all table definition.
0
 
amirmbAuthor Commented:
thank you, we were out of time. so we decided to add all of them in a composite id.
0
 
amirmbAuthor Commented:
The solution is not useful for us anymore
0
 
amirmbAuthor Commented:
we don't need the answer to this question anymore
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now