Hello all,
 
I apologise for newbie question, but I am not able to find the solution. I 
want to create 1 : 0..1 association between persons (dba."Osoby") and their 
database logins (dba."DbLogin"). Only some persons can sign up into the 
database. After some impasses (<one-to-one>, <one-to-many> and <many-to-one> 
back) I wrote the code that works but it uses composite-id for single column 
(stupidity). Please can somebody correct this code (verify tags, attributes, 
...) and at least get off the <composite-id> approach?
 
Thank you
 
 CREATE TABLE dba."Osoby"
(
  "IdOsoby" smallint NOT NULL DEFAULT 
nextval('dba."Osoby_IdOsoby_seq"'::regclass),
  "Email" character varying(30),
   ...
  CONSTRAINT "PK_OSOBY" PRIMARY KEY ("IdOsoby")
)
public class Osoba
{
 public virtual short? IdOsoby { get; set; }
 public virtual string Email { get; set; }
    ...
 public virtual IList<DbLogin> DbLogin { get; set; }
}
 
<class name="Osoba" table="`Osoby`">
  <id name="IdOsoby" column="`IdOsoby`" unsaved-value="null">
    <generator class="sequence">
      <param name="sequence">`Osoby_IdOsoby_seq`</param>
    </generator>
  </id>
  <property name="Email" column="`Email`" />
    ...
  <bag name="DbLogin" inverse="true" lazy="true" 
cascade="all-delete-orphan">
    <key column="`IdOsoby`" />
    <one-to-many class="DbLogin"/>
  </bag>
</class>
CREATE TABLE dba."DbLogin"
(
  "IdOsoby" smallint NOT NULL, 
  "UserName" character varying(16) NOT NULL,
  "Pwd" character varying(16) NOT NULL,
  CONSTRAINT "PK_DBLOGIN" PRIMARY KEY ("IdOsoby"),
  CONSTRAINT "FK_DBLOGIN_OSOBY" FOREIGN KEY ("IdOsoby")
      REFERENCES dba."Osoby" ("IdOsoby") MATCH SIMPLE
      ON UPDATE CASCADE ON DELETE RESTRICT
)
 
public class DbLogin
{
 public virtual string UserName { get; set; }
 public virtual string Pwd { get; set; }
 public virtual Osoba Osoba { get; set; }
 
  // Equals() and GetHashCode() method implementations required by 
<composite-id> tag in mappings file
}
 
<class name="DbLogin" table="`DbLogin`">
  <composite-id>
    <key-many-to-one name ="Osoba">
      <column name="`IdOsoby`" />
    </key-many-to-one>
  </composite-id>
  <property name ="UserName" column="`UserName`" />
  <property name="Pwd" column ="`Pwd`" />
</class>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to