Error parsing XML in Hibernate - java

I am getting error in my XML parsing in Hibernate
The mapping file is,
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-mapping>
<class name="Student" table="student" schema="db_1">
<id name="id" column="id" type="int">
<generator class="assigned"/>
</id>
<property name="name" column="name" type="string"/>
</class>
</hibernate-mapping>
The config file is,
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/db_1</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.show_sql">true</property>
<mapping resource="Student.hbm.xml"/>
<mapping resource="hibernate.hbm.xml"/>
</session-factory>
</hibernate-configuration>
I am getting the below error while running the code-
234 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : Student.hbm.xml
265 [main] ERROR org.hibernate.util.xml.ErrorLogger - Error parsing XML (5) : Element type "hibernate-mapping" must be declared.
265 [main] ERROR org.hibernate.util.xml.ErrorLogger - Error parsing XML (6) : Element type "class" must be declared.
265 [main] ERROR org.hibernate.util.xml.ErrorLogger - Error parsing XML (7) : Element type "id" must be declared.
265 [main] ERROR org.hibernate.util.xml.ErrorLogger - Error parsing XML (8) : Element type "generator" must be declared.
265 [main] ERROR org.hibernate.util.xml.ErrorLogger - Error parsing XML (10) : Attribute "column" must be declared for element type "property".
265 [main] ERROR org.hibernate.util.xml.ErrorLogger - Error parsing XML (10) : Attribute "type" must be declared for element type "property".
265 [main] ERROR org.hibernate.util.xml.ErrorLogger - Error parsing XML (2) : Element type "hibernate-mapping" must be declared.
265 [main] ERROR org.hibernate.util.xml.ErrorLogger - Error parsing XML (3) : Element type "class" must be declared.
281 [main] ERROR org.hibernate.util.xml.ErrorLogger - Error parsing XML (4) : Element type "id" must be declared.
281 [main] ERROR org.hibernate.util.xml.ErrorLogger - Error parsing XML (5) : Element type "generator" must be declared.
281 [main] ERROR org.hibernate.util.xml.ErrorLogger - Error parsing XML (7) : Attribute "column" must be declared for element type "property".
281 [main] ERROR org.hibernate.util.xml.ErrorLogger - Error parsing XML (7) : Attribute "type" must be declared for element type "property".
Initial SessionFactory creation failed.org.hibernate.InvalidMappingException: Unable to read XML
Could anyone help me and highlight the issues, eventhough I have validated the XML.

Please check if the jars of Hibernate are added properly in your dev environment.

You might be getting the error because you've wrong DTD declaration in your mapping file.
Change it to the following & then try:
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

Related

I'm getting XMLStreamException at [row,col]:[1,2]

I suddenly have started getting XMLStreamException in my project. Yesterday it worked just fine, today I made some minor changes and it's broken. I tried to rebase to previous versions, but nothing changed at all.
Here is my xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5433/logistica</property>
<property name="hibernate.connection.username">testUser</property>
<property name="hibernate.connection.password">pass</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQL9Dialect</property>
<mapping class="com.log.iei.logistica.data.entities.ClientEntity" />
<mapping class="com.log.iei.logistica.data.entities.ContractEntity" />
<mapping class="com.log.iei.logistica.data.entities.ContainerEntity" />
<mapping class="com.log.iei.logistica.data.entities.VehicleEntity" />
<mapping class="com.log.iei.logistica.data.entities.TransactionEntity" />
</session-factory>
</hibernate-configuration>
And exception:
org.hibernate.HibernateException: Error accessing stax stream
at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:107)
at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:65)
at org.hibernate.boot.cfgxml.internal.ConfigLoader.loadConfigXmlResource(ConfigLoader.java:57)
at org.hibernate.boot.registry.StandardServiceRegistryBuilder.configure(StandardServiceRegistryBuilder.java:165)
at org.hibernate.cfg.Configuration.configure(Configuration.java:258)
at org.hibernate.cfg.Configuration.configure(Configuration.java:244)
at com.log.iei.logistica.managers.HibernateSessionManager.getSessionFactory(HibernateSessionManager.java:18)
at com.log.iei.logistica.data.controllers.Services.GenericDao.getSession(GenericDao.java:78)
at com.log.iei.logistica.data.controllers.Services.GenericDao.findAll(GenericDao.java:58)
at com.log.iei.logistica.data.controllers.Services.VehicleService.findAll(VehicleService.java:50)
at com.log.iei.logistica.gui.cargo.CargoPage.init(CargoPage.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
.........
.......
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,2]
Message: The markup declarations contained or pointed to by the document type declaration must be well-formed.
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:604)
at com.sun.xml.internal.stream.XMLEventReaderImpl.peek(XMLEventReaderImpl.java:276)
at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:103)
... 36 more
I began having the same issue. I hadn't updated anything, but restarting tomcat failed with lots of new exceptions. I noticed the below file was updated today and wondered if it was the source (it is referenced in each of my entity mappings):
http://hibernate.org/dtd/hibernate-mapping-3.0.dtd
So I updated my mappings to use the DTD from here:"hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" - and that works. So it does appear to be caused by the Hibernate's updated DTD file.
I guess your options are:
figure out what hibernate wants in the updated dtd
use the dtd from another source like sourceforge
use the dtd from your hibernate jar like this: "classpath://org/hibernate/hibernate-mapping-3.0.dtd"

Invalid column name with Hibernate NamedQuery

My Hibernate hbm file looks like this. I had issues when running this query. The query was running fine on sql developer, but when running through my java application, it is throwing SQL Error: 17006, SQLState: 99999 error which is saying Invalid Column. I tried many ways to take columns off and change property names but could not find a solution.
2015-07-16 12:15:14,374 [http-bio-8080-exec-8] DEBUG com.adp.au.hibernate.HibernateUtils - HibernateUtils.closeSession(false) for session depth: [1]
2015-07-16 12:15:14,389 [http-bio-8080-exec-8] ERROR com.adp.au.timesheet.action.SubmitError - Client: [29010], User: [ADMIN] exception: [could not execute query]
2015-07-16 12:15:14,389 [http-bio-8080-exec-8] ERROR com.adp.au.timesheet.action.SubmitError - Client: [29010], User: [ADMIN] stacktrace: org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2545)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
at org.hibernate.loader.Loader.list(Loader.java:2271)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:316)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1842)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:157)
at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:890)
Could someone please look into this and help me?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class mutable="false" name="com.adp.au.timesheet.external.PLClient">
<id name="clientId"/>
<property name="branch"/>
<property name="name"/>
<property name="timesheetType"/>
<property name="costSplitting" type="yes_no"/>
<property name="payconReportCode"/>
<property name="ownEftUseInd" type="yes_no"/>
<property name="essUse" type="integer"/>
</class>
<sql-query name="plClient.byClientId.forABAFile" read-only="true">
<return alias="client" class="com.adp.au.timesheet.external.PLClient"/>
SELECT
TRIM(CLI_ID) AS {client.clientId},
OWN_EFT_USE_IND AS {client.ownEftUseInd}
FROM SAG.PL_CLI`
WHERE (TRIM(PL_CLI.CEASED_DATE) IS NULL OR PL_CLI.CEASED_DATE >TO_CHAR(SYSDATE, 'YYYYMMDD'))
AND PL_CLI.CLI_ID = RPAD(:clientId, 7)
</sql-query>
</hibernate-mapping>

Attribute "column"/"type" must be declared for element type "property"

I am a newbie to hibernate configuration.At my Eclipse project,I am getting the hibernate error above.
ERROR: org.hibernate.internal.util.xml.ErrorLogger - HHH000196: Error parsing XML (2) : Element type "hibernate-mapping" must be declared.
ERROR: org.hibernate.internal.util.xml.ErrorLogger - HHH000196: Error parsing XML (3) : Element type "class" must be declared.
ERROR: org.hibernate.internal.util.xml.ErrorLogger - HHH000196: Error parsing XML (4) : Element type "id" must be declared.
ERROR: org.hibernate.internal.util.xml.ErrorLogger - HHH000196: Error parsing XML (5) : Element type "generator" must be declared.
ERROR: org.hibernate.internal.util.xml.ErrorLogger - HHH000196: Error parsing XML (7) : Attribute "column" must be declared for element type "property".
ERROR: org.hibernate.internal.util.xml.ErrorLogger - HHH000196: Error parsing XML (7) : Attribute "type" must be declared for element type "property".
ERROR: org.hibernate.internal.util.xml.ErrorLogger - HHH000196: Error parsing XML (8) : Attribute "column" must be declared for element type "property".
ERROR: org.hibernate.internal.util.xml.ErrorLogger - HHH000196: Error parsing XML (8) : Attribute "type" must be declared for element type "property".
ERROR: org.hibernate.internal.util.xml.ErrorLogger - HHH000196: Error parsing XML (9) : Attribute "column" must be declared for element type "property".
ERROR: org.hibernate.internal.util.xml.ErrorLogger - HHH000196: Error parsing XML (9) : Attribute "type" must be declared for element type "property".
ERROR: org.hibernate.internal.util.xml.ErrorLogger - HHH000196: Error parsing XML (10) : Attribute "column" must be declared for element type "property".
ERROR: org.hibernate.internal.util.xml.ErrorLogger - HHH000196: Error parsing XML (10) : Attribute "type" must be declared for element type "property".
ERROR: org.hibernate.internal.util.xml.ErrorLogger - HHH000196: Error parsing XML (2) : Element type "hibernate-mapping" must be declared.
ERROR: org.hibernate.internal.util.xml.ErrorLogger - HHH000196: Error parsing XML (3) : Element type "class" must be declared.
ERROR: org.hibernate.internal.util.xml.ErrorLogger - HHH000196: Error parsing XML (4) : Element type "id" must be declared.
ERROR: org.hibernate.internal.util.xml.ErrorLogger - HHH000196: Error parsing XML (5) : Element type "generator" must be declared.
ERROR: org.hibernate.internal.util.xml.ErrorLogger - HHH000196: Error parsing XML (7) : Attribute "column" must be declared for element type "property".
ERROR: org.hibernate.internal.util.xml.ErrorLogger - HHH000196: Error parsing XML (7) : Attribute "type" must be declared for element type "property".
ERROR: org.hibernate.internal.util.xml.ErrorLogger - HHH000196: Error parsing XML (8) : Attribute "column" must be declared for element type "property".
ERROR: org.hibernate.internal.util.xml.ErrorLogger - HHH000196: Error parsing XML (8) : Attribute "type" must be declared for element type "property".
ERROR: org.hibernate.internal.util.xml.ErrorLogger - HHH000196: Error parsing XML (9) : Attribute "column" must be declared for element type "property".
ERROR: org.hibernate.internal.util.xml.ErrorLogger - HHH000196: Error parsing XML (9) : Attribute "type" must be declared for element type "property".
ERROR: org.hibernate.internal.util.xml.ErrorLogger - HHH000196: Error parsing XML (10) : Attribute "column" must be declared for element type "property".
ERROR: org.hibernate.internal.util.xml.ErrorLogger - HHH000196: Error parsing XML (10) : Attribute "type" must be declared for element type "property".
Exception in thread "main" org.hibernate.InvalidMappingException: Unable to read XML
at org.hibernate.internal.util.xml.MappingReader.legacyReadMappingDocument(MappingReader.java:375)
at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:304)
at org.hibernate.cfg.Configuration.add(Configuration.java:516)
at org.hibernate.cfg.Configuration.add(Configuration.java:512)
at org.hibernate.cfg.Configuration.add(Configuration.java:686)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:769)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2255)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2227)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2207)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2160)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2075)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2054)
at com.test.Main.main(Main.java:41)
Caused by: org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 20; Element type "hibernate-mapping" must be declared.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(XMLDTDValidator.java:1906)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:742)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:379)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:605)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3138)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:880)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:117)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.internal.util.xml.MappingReader.legacyReadMappingDocument(MappingReader.java:325)
... 12 more
In the PERSONDB class, there are five columns named as PERSON_ID, PERSON_FIRSTNAME, PERSON_LASTNAME, PERSON_GENDER, PERSON_AGE.
domain-classes.hbm.xml:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-mapping>
<class table="Person" lazy="false" name="com.hibernate.data.Person" >
<id column="PERSON_ID" type="int" name="id" >
<generator class="increment"/>
</id>
<property column="PERSON_FIRSTNAME" type="string" name="firstName"/>
<property column="PERSON_LASTNAME" type="string" name="lastName"/>
<property column="PERSON_GENDER" type="string" name="gender"/>
<property column="PERSON_AGE" type="integer" name="age" />
</class>
</hibernate-mapping>
hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/PERSONDB</property>
<property name='connection.username'>root</property>
<property name='connection.password'>root</property>
<!-- SQL dialect -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Specify session context -->
<property name="hibernate.current_session_context_class">org.hibernate.context.internal.ThreadLocalSessionContext</property>
<!-- Show SQL -->
<property name="show_sql">true</property>
<!-- Referring Mapping File -->
<mapping resource="domain-classes.hbm.xml"/>
<mapping class="src/main/java/com.hibernate.data/Person"/>
</session-factory>
</hibernate-configuration>
Person.java:
package com.hibernate.data;
public class Person {
private int id;
private String firstName;
private String lastName;
private String gender;
private int age;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
How can I fix this?
I changed
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
to
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
Now, it works.
I was facing some issues with the following declaration
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
With Hibernate 5, I had to change it to the following to work.
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
Review your code
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
Change this to:
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

MappingException .hibernate mapping fails for classes in different packages

while using hibernate,I came across this problem mapping classes in two different packages.
I have a myapp.domain.ItemforSale class which is to be mapped to myapp.cart.CartItem
I created CartItem.hbm.xml as below
<hibernate-mapping package="myapp.cart">
<class name="CartItem" table="CARTITEM">
<id name="cartItem_id" column="CARTITEM_ID" type="long">
<generator class="native"/>
</id>
<property name="quantity" type="int" column="QUANTITY" />
<many-to-one name="itemforsale" class="myapp.domain.ItemforSale" column="ITEM_FORSALE_ID" lazy="false" />
</class>
...
I have a unidirectional mapping from CartItem to ItemForSale entity.While running a test on saving ItemForSale instances to db..I got this error
506 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
506 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
571 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : myapp/domain/ItemForSale.hbm.xml
636 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: bookshop.domain.ItemForSale ->ITEMFORSALE
...
746 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : myapp/cart/CartItem.hbm.xml
751 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: myapp.cart.CartItem -> CARTITEM
...
org.hibernate.MappingException: Association references unmapped class: myapp.domain.CartItem
I removed the package attribute from element and put fully classified class names.Still I get the same exception..
<hibernate-mapping>
<class name="myapp.cart.CartItem" table="CARTITEM">
<id name="cartItem_id" column="CARTITEM_ID" type="long">
<generator class="native"/>
</id>
<property name="quantity" type="int" column="QUANTITY" />
<many-to-one name="itemforsale" class="myapp.domain.ItemForSale" column="ITEM_FORSALE_ID" lazy="false" />
</class>
As a final attempt,I moved the CartItem to myapp.domain package and everything works!
Any idea why this happens?It won't make sense in my app to move myapp.cart.CartItem to myapp.domain ..Any help greatly appreciated.
thanks
mark
org.hibernate.MappingException: Association references unmapped class: myapp.domain.CartItem
This only means it is searching for CartItem on myapp.domain package but your class is actually in myapp.cart package. So basically the hibernate mapping that you have shown is correct, but I think there could be some issues on your java class. Could you please display your java classes related to your issue?
Or you haven't display other related hibernate mapping that could cause this exception.
Also make sure all mappings in hibernate.cfg.xml or Spring's applicationContext corresponds to actual mappings.

Mapping problem with Hibernate

I am new to hibernate and i am having trouble with specifying the location of the mapping file in hibernate.cfg.xml file.
I have created an Event object in org.hibernate.tutorial.chapter1.domain.Event.java package with its corresponding Event.hbm.xml file in the same location.
I am trying to specify the location in the hibernate.cfg.xml mapping tag but I am getting an InvalidMappingException ().
I have added to the post: the exception, the mapping from the mapping file and the project file structure.
any advice would be great.
484 [main] ERROR
org.hibernate.util.xml.ErrorLogger -
Error parsing XML (1) : cvc-elt.1:
Cannot find the declaration of element
'hibernate-mapping'. 495 [main] ERROR
org.hibernate.util.xml.ErrorLogger -
Error parsing XML (2) : cvc-elt.1:
Cannot find the declaration of element
'hibernate-mapping'. Initial
SessionFactory creation
failed.org.hibernate.InvalidMappingException:
Unable to read XML
<!-- Names the annotated entity class -->
<mapping resource="org/hibernate/tutorial/chapter1/domain/Event.hbm.xml"/>
Make sure you have a DOCTYPE in your Event.hbm.xml at the top of the XML content such as:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.tutorial.domain">
[...]
</hibernate-mapping>
My problem was that my XML file was missing :
<?xml version="1.0" encoding='utf-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
after inserting this to the beginning of the XML file everything turned out great.
Thanks!

Categories

Resources