- This topic has 3 replies, 2 voices, and was last updated 18 years, 1 month ago by Riyad Kalla.
-
AuthorPosts
-
springwinder2Membercreate 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
Riyad KallaMemberFor 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)
springwinder2Membercreate table “nzzj_ps”.”dbo”.”student”(
“id” int not null,
“stuName” varchar(50) null,
constraint “id” primary key (“id”)
)
goalter 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”)
gocreate table “nzzj_ps”.”dbo”.”certificate”(
“id” int not null,
“cerName” varchar(50) null,
constraint “id2” primary key (“id”)
)
goalter 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”)
goStudent.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!
Riyad KallaMemberMy 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.
-
AuthorPosts