facebook

how to generation one-to-one mapping relation

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #258736 Reply

    create table “nzzj_ps”.”dbo”.”student”(
    “id” int identity not null,
    “stu_name” varchar(50) null,
    “team_id” int null,
    constraint “PK__student__7C8F6DA6” primary key (“id”)
    )
    create table “nzzj_ps”.”dbo”.”certificate”(
    “id” int not null,
    “cer_name” varchar(50) null,
    constraint “PK__certificate__7211DF33” primary key (“id”),
    constraint “FK_certificate_student”
    foreign key (“id”)
    references “nzzj_ps”.”dbo”.”student”(“id”)
    )

    <hibernate-mapping>
    <class name=”org.nercita.domain.Student” table=”student” schema=”dbo” catalog=”nzzj_ps”>
    <id name=”id” type=”java.lang.Integer”>
    <column name=”id” />
    <generator class=”native”></generator>
    </id>

    <property name=”stuName” type=”java.lang.String”>
    <column name=”stu_name” length=”50″ />
    </property>
    <set name=”certificates” inverse=”true”>
    <key>
    <column name=”id” not-null=”true” unique=”true” />
    </key>
    <one-to-many class=”org.nercita.domain.Certificate” />
    </set>
    </class>
    </hibernate-mapping>

    why not it generation the one-to-one mapping?
    database:sqlserver2000
    ide:myeclipse5.0.1

    #258804 Reply

    Riyad Kalla
    Member

    For a o2o don’t you need student to have a FK reference on the certificate as well? (I was under the impression that o2o were bi-directional)

    #258827 Reply

    create table “nzzj_ps”.”dbo”.”student”(
    “id” int not null,
    “stuName” varchar(50) null,
    constraint “id” primary key (“id”)
    )
    go

    alter table “nzzj_ps”.”dbo”.”student”
    add constraint “fk1”
    foreign key (“id”)
    references “nzzj_ps”.”dbo”.”certificate”(“id”)
    go
    create unique index “id” on “nzzj_ps”.”dbo”.”student”(“id”)
    go

    create table “nzzj_ps”.”dbo”.”certificate”(
    “id” int not null,
    “cerName” varchar(50) null,
    constraint “id2” primary key (“id”)
    )
    go

    alter table “nzzj_ps”.”dbo”.”certificate”
    add constraint “fk2”
    foreign key (“id”)
    references “nzzj_ps”.”dbo”.”student”(“id”)
    go
    create unique index “id2” on “nzzj_ps”.”dbo”.”certificate”(“id”)
    go

    Student.hbm.xml
    <hibernate-mapping>
    <class name=”org.nercita.domain.Student” table=”student” schema=”dbo” catalog=”nzzj_ps”>
    <id name=”id” type=”java.lang.Integer”>
    <column name=”id” />
    <generator class=”native”></generator>
    </id>
    <many-to-one name=”certificate” class=”org.nercita.domain.Certificate” update=”false” insert=”false” fetch=”select”>
    <column name=”id” not-null=”true” unique=”true” />
    </many-to-one>
    <property name=”stuName” type=”java.lang.String”>
    <column name=”stuName” length=”50″ />
    </property>
    <set name=”certificates” inverse=”true”>
    <key>
    <column name=”id” not-null=”true” unique=”true” />
    </key>
    <one-to-many class=”org.nercita.domain.Certificate” />
    </set>
    </class>
    </hibernate-mapping>

    Certificate.hbm.xml
    <hibernate-mapping>
    <class name=”org.nercita.domain.Certificate” table=”certificate” schema=”dbo” catalog=”nzzj_ps”>
    <id name=”id” type=”java.lang.Integer”>
    <column name=”id” />
    <generator class=”native”></generator>
    </id>
    <many-to-one name=”student” class=”org.nercita.domain.Student” update=”false” insert=”false” fetch=”select”>
    <column name=”id” not-null=”true” unique=”true” />
    </many-to-one>
    <property name=”cerName” type=”java.lang.String”>
    <column name=”cerName” length=”50″ />
    </property>
    <set name=”students” inverse=”true”>
    <key>
    <column name=”id” not-null=”true” unique=”true” />
    </key>
    <one-to-many class=”org.nercita.domain.Student” />
    </set>
    </class>
    </hibernate-mapping>

    With the bi-directional relation it still not work very well.
    I create table with the sql above.
    But it can not generation the one-to-one mapping.

    thanks a lot!

    #258869 Reply

    Riyad Kalla
    Member

    My appologies, I checked on this and o2o mappings are not supported at this time neither are m2m, but we hope to support them in the future.

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: how to generation one-to-one mapping relation

You must be logged in to post in the forum log in