gavin wrote:
Your mapping looks perfect to me. I don't think the bit you just showed is what is causing the exception. I bet you have other stuff you are hiding from me :)
Hi , I cannot find what information I hide ....
But ... after I migrate to Hibernate 2.1 beta 2 ,
the error messages are different :
First , it says that the second key int the Set is not allowed :
Code:
<set name="ClassBSet" table="ClassB" cascade="all" order-by="key3 asc">
<key column="key1"/>
<key column="key2"/> (This is Line 22)
<one-to-many class="foo.ClassB"/>
</set>
Error parsing XML: XML InputStream(22)
org.xml.sax.SAXParseException: 元件 "set" 在此不允許 "key"。 (it is big5 output message , means 'key' is not allowed in the element 'set')
at org.apache.crimson.parser.Parser2.error(Parser2.java:3160)
at org.apache.crimson.parser.ValidatingParser$ChildrenValidator.consume(ValidatingParser.java:349)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1317)
at org.apache.crimson.parser.Parser2.content(Parser2.java:1779)
INFO: processing one-to-many association mappings
2003/9/1 05:03:48 net.sf.hibernate.cfg.Binder bindCollectionSecondPass
INFO: Mapping collection:
foo.ClassA.ClassBSet -> ClassB
2003/9/1 05:03:48 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-one association property references
2003/9/1 05:03:48 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
Error while initialize foo HibernateSession's sessionFactory
net.sf.hibernate.MappingException: Foreign key (ClassB [key2])) must have same number of columns as the reference primary key (ClassA [key1,key2])
at net.sf.hibernate.mapping.ForeignKey.setReferencedTable(ForeignKey.java:56)
at net.sf.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:557)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:651)