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

Posted on 2011-05-05
Last Modified: 2012-05-11
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 name="customerId" type="integer">
                <column name="customer_id" not-null="true" />
        <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" />

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?
Question by:amirmb
    LVL 20

    Expert Comment

    by:Amitkumar Panchal
    Please share all table definition.

    Accepted Solution

    thank you, we were out of time. so we decided to add all of them in a composite id.

    Author Comment

    The solution is not useful for us anymore

    Author Closing Comment

    we don't need the answer to this question anymore

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Suggested Solutions

    Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
    Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
    Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now