Quote:
My question is: Can I map <subclass> element into <component> element?? 'cause the code below don´t compile, and I don't know why.
If there is other error plese notify me!!
Thank you, Gervasio. (Sorry by me english, I speak spanish...)
Hibernate version: 2.1.8
Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="modelo.Reserva" table="reservas">
<id name="idReserva" column="idReserva" type="long">
<generator class="increment"/>
</id>
<property name="fecha" type="date"/>
<many-to-one name="base" cascade="none" column="idBase" foreign-key="FK_BASE_RESERVA" not-null="true"/>
<component name="formaPago" class="modelo.PagoReserva">
<property name="precioTotal"/>
<subclass name="modelo.PagoConTarjeta" discriminator-value="PT">
<property name="valorReserva"/>
<property name="nroTarjeta"/>
<many-to-one name="marcaTarjeta" cascade="none" column="idMarcaTarjeta" foreign-key="FK_MARCAT_RESERVA" not-null="true"/>
</subclass>
<subclass name="modelo.PagoConPuntos" discriminator-value="PP">
</subclass>
</component>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
No code, don´t map
Full stack trace of any exception that occurs:
INFO: Mapping resource: modelo/Reserva.hbm.xml
28-feb-2005 10:57:13 net.sf.hibernate.util.XMLHelper$ErrorLogger error
GRAVE: Error parsing XML: XML InputStream(24) The content of element type "component" must match "(meta*,parent?,(property|many-to-one|one-to-one|component|dynamic-component|any|map|set|list|bag|array|primitive-array)*)".
net.sf.hibernate.MappingException: Error reading resource: modelo/Reserva.hbm.xml
at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:358)
at conexion.Conexion.main(Conexion.java:20)
Caused by: net.sf.hibernate.MappingException: invalid mapping
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:288)
at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:355)
... 1 more
Caused by: org.xml.sax.SAXParseException: The content of element type "component" must match "(meta*,parent?,(property|many-to-one|one-to-one|component|dynamic-component|any|map|set|list|bag|array|primitive-array)*)".
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.endElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:339)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:287)
... 2 more
Name and version of the database you are using: My SQL 4.1.9
The generated SQL (show_sql=true): --------
Debug level Hibernate log excerpt: ?????