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

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"

Related

Netbeans 8.x + hibernate + postgreSQL : No tables found in reverse engineering

I use neatbeans with hibernate + postgreSQL.
In postgreSQL I have 1 table : "test" with 3 columns.
I created the hibernate.cfg.
<?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.PostgreSQLDialect</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/test</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">root</property>
</session-factory>
</hibernate-configuration>
Now I want to create the reverse engineering file for map my table, the problem is I haven't output (in table field).
In my libraries I have:
Hibernate 4.3.x
postgresql-9.3-1102.jdbc41
JDK 8
With NetBeans, when I go to Service area I can connect to my database, and see my tables with his values.
Maybe an idea, when I created the hibernate.cfg, I chose my new Driver -> Add postgresql-9.3-1102.jdbc41.jar and when I click on "find" Driver Class I have the error message: Driver class is missing. I don't know if that could be the problem.
Do you have any idea ?
Thanks for your help !

Error parsing configuration/hibernate.cfg.xml?

My XML file
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.sourceforge.net/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:#192.168.252.128:1521:orcl</property>
<property name="connection.username">system</property>
<property name="connection.passowrd">manager</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">update</property>
<mapping class="com.nttdata.domain.Employee"/>
</session-factory>
</hibernate-configuration>
Console after execution ::
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.HibernateException: problem parsing configuration/hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1222)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1161)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1147)
at com.nttdata.util.HibernateUtil.getSessionFactory(HibernateUtil.java:11)
at com.nttdata.dao.EmployeeDao.saveEmployee(EmployeeDao.java:13)
at com.nttdata.client.Driver.main(Driver.java:10)
Caused by: org.dom4j.DocumentException: www.hibernate.sourceforge.net Nested exception: www.hibernate.sourceforge.net
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1217)
... 5 more
What can be the error any help??
Try changing the DOCTYPE to this:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<!DOCTYPE hibernate-configuration SYSTEM
"classpath://org/hibernate/hibernate-configuration-3.0.dtd">
This means that hibernate will load the DTD from classpath - it is usually included in hibernate jar in org/hibernate directory.
However, we use hibernate 3.5.6 - I don't hnow if this approach still works in the newer version - give it a try. The benefit of this is that you are completely independent on internet connection, proxies and so on.
Hibernate Configuration File Location
The first solution was to provide the DTD file location in the system using classpath. So the DocType that worked offline would be;
<!DOCTYPE hibernate-configuration SYSTEM
"classpath://org/hibernate/hibernate-configuration-3.0.dtd">
Use SourceForge DTD URL with SYSTEM
Another solution I found working is when I change the DTD URL to SourceForge and changed the declaration from PUBLIC to SYSTEM.
So below will also work if your system is offline.
<!DOCTYPE hibernate-configuration SYSTEM
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

Configuring hibernate.cfg.xml file

I am new to Hibernate, so I have few dumb questions hope someone would be able to assist me. I have a query in regards to configuring hibernate file i.e. hibernate.cfg.xml file. Normally we configure it as below :
<?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="hbm2ddl.auto">update</property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="connection.url">jdbc:oracle:thin:#localhost:1521:xe</property>
<property name="connection.username">system</property>
<property name="connection.password">oracle</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<mapping resource="employee.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Where the considers relevant mapping files. Lets say I have another mapping file, call it company.hbm.xml file and have a one-to-many relationship with employee.hbm.xml file. So, as and when the number of mapping files increases we include them into tag.
Query : How is it different to include multiple mapping files with individual tag from having just a single mapping file with all the relevant mappings.
Appreciate your response
Because such separation is cleaner. Single file with whole configuration tends to grow up and to become a yet another huge, unmaintainable and unreadable XML file.
Please also note, that using annotations right inside your model classes seems to be the right way for you (just as #Shiju Babu stated).

Hibernate: Can't connect to MySQL database

I'm struggling to get my program to connect to a MySQL database with Hibernate.
I simply want to connect to it so i can usee Hibernate tools to reverse engineer a few tables in the database.
When i use MySQL Workbench to connect to the database from the same machine, it works.
Here's my hibernate.cfg.xml file:
<?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.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://www.soosthebasement.nl:3306/soos_thebasement</property>
<property name="hibernate.connection.username">removed</property>
<property name="hibernate.connection.password">removed</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
</session-factory>
</hibernate-configuration>
The password contains some weird chars, like >, which when creating the cfg file got parsed into >. Could that have something to do with it?
Turns out i used the wrong URL.
Even though the URL listed in the question points to the correct website, it doesn't actually point to the database host.

MappingNotFoundException when running queries in IntelliJ Hibernate console

I'm trying to run HQL queries in IntelliJ's Hibernate Console. I've added the datasource to the Data Sources view and added my hibernate.cfg.xml to the Hibernate facet such that in appears in the Persistence view. The content of hibernate.cfg.xml is:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:mysql://localhost/mmanager</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.username">root</property>
<property name="connection.password">password</property>
<property name="dialect">com.puca.core.util.db.MySQLInnoDBDialect</property>
<!-- mapping files -->
<mapping resource="com/puca/messagemanager/api/model/XmlApiDlrMapping.hbm.xml"/>
</session-factory>
</hibernate-configuration>
The .hbm.xml is shown in green, whereas if I change it to a file that doesn't exist it is shown in red, so it seems that IntelliJ can find it. However, if I run a simple query in the console like:
from XmlApiDlrMapping xmlApiDlrMapping
where xmlApiDlrMapping.retries = 5
I get an error:
java.lang.RuntimeException: org.hibernate.MappingNotFoundException: resource: com/puca/messagemanager/api/model/XmlApiDlrMapping.hbm.xml not found
at org.hibernate.cfg.Configuration.addResource(Configuration.java:563)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1587)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
I'm using IntelliJ 10.5.4.
It's exactly what it says in the error message. The mapping XML file is missing:
com/puca/messagemanager/api/model/XmlApiDlrMapping.hbm.xml
These files are used to map table columns to your entity class fields.
http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/tutorial.html#tutorial-firstapp-mapping

Categories

Resources