Hibernate Mapping Problem with Relationsships


General J2EE: Hibernate Mapping Problem with Relationsships

  1. Hey,
    I got a quite problematic thing here, I have got 3 mappings, system, customer, systemtype.
    To keep my database clean I used some foreign keys. After creating my mapping files I got stuck at my dao test.
    Here is the top-part of my System.hbm.xml:

      <composite-id name="id" class="itecon.bo.model.SystemId">
          <key-property name="Scid" type="java.lang.Long">
            <column name="SCID" scale="22" precision="0" not-null="true" sql-type="NUMBER" />
          <key-property name="Ssystemtype" type="java.lang.Long">
            <column name="SSYSTEMTYPE" scale="22" precision="0" not-null="true" sql-type="NUMBER" />
        <many-to-one name="Customer" class="itecon.bo.model.Customer" update="false" insert="false">
          <column name="SCID" scale="22" precision="0" not-null="false" />
        <many-to-one name="Systemtype" class="itecon.bo.model.Systemtype" update="false" insert="false">
          <column name="SSYSTEMTYPE" scale="22" precision="0" not-null="false" />
        <property name="Sid" type="java.lang.Long">
          <column name="SID" scale="22" precision="0" not-null="true" unique="true" sql-type="NUMBER" />

    As explained above, system references the primary keys of systemtype and customer, but my problem is, that Sid should be auto_incremental but <generator> is not allowed.

    So my question is: Do I have an architectural problem, or are there any workaroungs to fix this?

    I thank in advance for all tips and hints.

    Bye Johannes
  2. You will get better support at the hibernate forums:)

    Hibernate does not like composit keys. You will run into more difficulties if you use them. In this case they are not needed.