i'm using hibernate 2.0 and mySQL 4.01 with Tomcat 1.4, and i caugh a strange bug,
my old mapping is like this :
<class name="eHap.entity.Nurse" table="nurse">
<id name="nurseId" type="java.lang.String" column="nurse_id">
<generator class="assigned" />
</id>
...
<set name="scheduleList" table="SCHEDULE " order-by="weekday ASC" where="status>0" >
<key column="nurse_id"/>
<one-to-many class="eHap.entity.Schedule"/>
</set>
...
</class>
and
<class name="eHap.entity.Schedule" table="schedule">
..
<many-to-one name="ownNurse" class="eHap.entity.Nurse" not-null="true">
<column name="nurse_id" />
</many-to-one>
...
</class>
my data script is like this :
CREATE TABLE nurse (
nurse_id VARCHAR(15) NOT NULL
....
, PRIMARY KEY (nurse_id)
);
CREATE TABLE schedule
(
schedule_id varchar(32) NOT NULL,
nurse_id varchar(15) NOT NULL,
agency_id varchar(32) NOT NULL,
CONSTRAINT schedule_pkey PRIMARY KEY (schedule_id),
CONSTRAINT fk_schedule_1 FOREIGN KEY (nurse_id) REFERENCES nurse (nurse_id) ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_schedule_2 FOREIGN KEY (agency_id) REFERENCES agency (agency_id) ON UPDATE NO ACTION ON DELETE NO ACTION
);
and the table Agency and nurse is hasnt got any reference
In the first mapping class, i've used table nurse(in lowercase) and table SCHEDULE(in Upper) in the set nam scheduleList,
in the second class, the table is schedule (Lowercase)..
And everything is ok,
but when i changed all table name into UPPERCASE or lowercase, it appeared a bug like this :
net.sf.hibernate.MappingException: Foreign key (schedule[schedule_id])) must have same number of columns as the referenced primary key (schedule[nurse_id,agency_id,schedule_id])
at net.sf.hibernate.mapping.ForeignKey.setReferencedTable(ForeignKey.java:60)
at net.sf.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:649)
Plz help me !
Thank you all.
|