Error while parsing file: Member.hbm.xml - java

I got this problem and don't know how to handle it.
Here is my Member.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 12.07.2013 13:28:27 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="MyApp.WebApp.model.Member" table="MEMBER">
<id name="id" type="java.lang.Long" access="field">
<column name="ID" />
<generator class="assigned" />
</id>
<property name="name" type="java.lang.String">
<column name="NAME" />
</property>
<property name="surname" type="java.lang.String">
<column name="SURNAME" />
</property>
<property name="email" type="java.lang.String">
<column name="EMAIL" />
</property>
<property name="username" type="java.lang.String">
<column name="USERNAME" />
</property>
<property name="password" type="java.lang.String">
<column name="PASSWORD" />
</property>
<property name="result" type="java.lang.String" access="field">
<column name="RESULT" />
</property>
</class>
</hibernate-mapping>
My hbm.cfg.xml:
<?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.password">root</property>
<property name="hibernate.connection.url">
jdbc:mysql://localhost:3306/test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<mapping resource="MyApp/WebApp/model/Member.hbm.xml"/>
</session-factory>
the exception:
13:31:48,073 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC00001: Failed to start service jboss.persistenceunit."WebApp.war#primary": org.jboss.msc.service.StartException in service jboss.persistenceunit."WebApp.war#primary": Failed to start service
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1767) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) [classes.jar:1.6.0_51]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) [classes.jar:1.6.0_51]
at java.lang.Thread.run(Thread.java:680) [classes.jar:1.6.0_51]
Caused by: org.hibernate.MappingException: Error while parsing file: Member.hbm.xml
at org.hibernate.ejb.Ejb3Configuration.addClassesToSessionFactory(Ejb3Configuration.java:1255)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1047)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:692)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:72)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:162)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.start(PersistenceUnitServiceImpl.java:85)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
... 3 more
Caused by: org.hibernate.InvalidMappingException: Unable to read XML
at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:106)
at org.hibernate.cfg.Configuration.add(Configuration.java:474)
at org.hibernate.cfg.Configuration.add(Configuration.java:470)
at org.hibernate.cfg.Configuration.add(Configuration.java:643)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:681)
at org.hibernate.ejb.Ejb3Configuration.addClassesToSessionFactory(Ejb3Configuration.java:1247)
... 10 more
Caused by: org.dom4j.DocumentException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory Nested exception: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:76)
... 15 more

Related

Table not mapped [FROM Table]

I'm trying to make a query to the database and I get this:
java.lang.IllegalArgumentException:
org.hibernate.hql.internal.ast.QuerySyntaxException: generalsetup is
not mapped [FROM generalsetup]
org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:133)
org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:157)
org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:164)
org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:670)
org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:103)
org.apache.jsp.Environments_jsp._jspService(Environments_jsp.java:188)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
IMPORTANT: I can write to the database but I can't read.
This is my code that tries to get a list from (I have a error mark under generalsetup:
SessionFactory factory = HibernateUtil.GetSessionFactory();
Session hibernateSession = factory.openSession();
Transaction tx = null;
try {
tx = hibernateSession.beginTransaction();
List environments = hibernateSession.createQuery("FROM generalsetup").list();
for (Iterator iterator = environments.iterator(); iterator.hasNext();) {
Environment environment = (Environment) iterator.next();
System.out.println(environment.getName());
}
tx.commit();
} catch (HibernateException e) {
if (tx!=null) tx.rollback();
e.printStackTrace();
} finally {
hibernateSession.close();
}
My GeneralSetup.hbm.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.atp.servlets.Model.GeneralSetup" table="generalsetup">
<meta attribute="class-description">
This class contains the general_setup detail.
</meta>
<id name="id" type="int" column="idGeneralSetup">
<generator class="native"/>
</id>
<property name="name" column="name" type="string"/>
<property name="hasProfile7" column="hasProfile7" type="boolean"/>
<property name="hasWebAdmin" column="hasWebAdmin" type="boolean"/>
<property name="hasWebClient" column="hasWebClient" type="boolean"/>
<property name="hasWebCSR" column="hasWebCSR" type="boolean"/>
<property name="profile7Branch" column="profile7Branch" type="string"/>
<property name="webAdminBranch" column="webAdminBranch" type="string"/>
<property name="webClientBranch" column="webClientBranch" type="string"/>
<property name="webCSRBranch" column="webCSRBranch" type="string"/>
<property name="initialDayEnd" column="initialSystemDate" type="string"/>
<property name="finalDayEnd" column="finalSystemDate" type="string"/>
<property name="amountOfDayEnds" column="amountOfDayEnds" type="int"/>
<property name="user" column="user" type="string"/>
</class>
</hibernate-mapping>
my config:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<!-- Assume test is the database name -->
<property name="hibernate.connection.url">
jdbc:mysql://localhost/mydb
</property>
<property name="hibernate.connection.username">
root
</property>
<property name="hibernate.connection.password">
qetwr123
</property>
<!-- List of XML mapping files -->
<mapping resource="com/atp/servlets/Model/GeneralSetup.hbm.xml"/>
</session-factory>
</hibernate-configuration>

Invalid Mapping Exception in hibernate.hbm.xml

I am posting my hbm file with the cfg file along with my error log. I found my questions based on similar problems are tried out their solution too but still my error is not fading away.
log
Initial SessionFactory creation failed.org.hibernate.InvalidMappingException: Could not parse mapping document from resource net/viralpatel/hibernate/Employee.hbm.xml
Exception in thread "main" java.lang.ExceptionInInitializerError
at net.viralpatel.hibernate.HibernateUtil.buildSessionFactory(HibernateUtil.java:18)
at net.viralpatel.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:8)
at net.viralpatel.hibernate.Main.main(Main.java:13)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from resource net/viralpatel/hibernate/Employee.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:569)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1584)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1552)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1531)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1505)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1425)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1411)
at net.viralpatel.hibernate.HibernateUtil.buildSessionFactory(HibernateUtil.java:14)
... 2 more
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from input stream
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:508)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:566)
... 9 more
Caused by: org.dom4j.DocumentException: Error on line 9 of document : The element type "generator" must be terminated by the matching end-tag "</generator>". Nested exception: The element type "generator" must be terminated by the matching end-tag "</generator>".
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:499)
... 10 more
Employee.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Employee" table="EMPLOYEE" >
<id name="employeeId" column="EMPLOYEE_ID">
<generator class="native">
</id>
<one-to-one name="employeeDetail" class="net.viralpatel.hibernate.EmployeeDetail"
cascade="save-update"></one-to-one>
<property name="firstname" column="firstname" />
<property name="lastname" column="lastname" />
<property name="birthDate" type="date" column="birth_date" />
<property name="cellphone" column="cell_phone" />
</class>
hibernate.cfg.xml
<!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="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/hibernate</property>
<property name="connection.username">root</property>
<property name="connection.password">tcs#1234</property>
<property name="connection.pool_size">1</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">update</property>
<mapping resource="net/viralpatel/hibernate/EmployeeDetail.hbm.xml"/>
<mapping resource="net/viralpatel/hibernate/Employee.hbm.xml"/>
</session-factory>
In your Employee.hbm.xml you're not closing the generator tag.
Replace
<generator class="native">
by this
<generator class="native"/>
By looking at stack trace, you have not end the generator tag properly.
Please change your employee.hbm.xml file to end the <generator> element properly.
For Ex: It should be <generator class="native"/>

Criteria.list() returns an empty collection, no query executed

I want to get a collection of Event.class objects, but criteria.list() returns an empty collection. I also have show_sql = true property, but there is no sql's in console
My hibernate.cfg.xml
<hibernate-configuration>
<session-factory>
<!-- hibernate dialect -->
<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/inspector_database</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">********</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<!-- Simple memory-only cache -->
<property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- <mapping class="mainobjects.Driver"/> -->
<property name="hibernate.show_sql">true</property>
<mapping class="inspectorserver.entities.Driver" resource="inspectorserver/entities/Driver.hbm.xml"/>
<mapping class="inspectorserver.entities.Event" resource="inspectorserver/entities/Event.hbm.xml"/>
<mapping class="inspectorserver.entities.Violation" resource="inspectorserver/entities/Violation.hbm.xml"/>
<mapping class="inspectorserver.entities.Car" resource="inspectorserver/entities/Car.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Event.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 18.03.2016 21:32:29 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="inspectorserver.entities.Event" table="EVENT" lazy="false">
<id name="id" type="java.lang.String">
<column name="ID" />
<generator class="assigned" />
</id>
<property name="eventDate" type="java.lang.String">
<column name="EVENTDATE" />
</property>
<property name="feeSum" type="java.lang.String">
<column name="FEESUM" />
</property>
<property name="driverLicenseNumber" type="java.lang.String">
<column name="DRIVERLICENSENUMBER" />
</property>
<property name="carVINCode" type="java.lang.String">
<column name="CARVINCODE" />
</property>
<property name="syncStatus" type="int">
<column name="SYNCSTATUS" />
</property>
</class>
</hibernate-mapping>
This is how I get the collection:
Session session = MyHibernateUtil.getSessionFactory().openSession();
Criteria criteria = session.createCriteria(Event.class);
criteria.list(); //empty
Solved this by removing class="inspectorserver.entities.Driver(Event, etc.)" from tag

Cannot modify hibernate settings

I created hibernate.cfg.xml and UserDataFromDb.hbm.xml and tried to put it in a correct place. First time there was exception like "Cannot find hibernate.cfg.xml", but after several replacement correct place was found. New exception was (with except of lots of other trace):
Caused by: org.hibernate.HibernateException: Enum class not found
Caused by: java.lang.ClassNotFoundException: net.codejava.hibernate.Gender
It is ok, because I've forgotten to change tutorial sample code and print my class name. I've fixed this problem, so, now there are no mentions about class Gender in UserDataFromDb.hbm.xml. Problem is certainly the same.
I've replaced both UserDataFromDb.hbm.xml and hibernate.cfg.xml to desktop and even renamed them. So, no there are no either UserDataFromDb.hbm.xml or hibernate.cfg.xml files on my computer (instead of them -- UserData11FromDb.hbm.xml and hiber111nate.cfg.xml on desktop). Exception are still the same:
Caused by: org.hibernate.HibernateException: Enum class not found
Caused by: java.lang.ClassNotFoundException: net.codejava.hibernate.Gender
though neither Gender class nor even configuration and mapping files exist on computer.
Rebooting computer makes no effect.
OS Windows 7, Hibernate 4.3.6
Config file:
`
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<!-- Assume test is the database name -->
<property name="hibernate.connection.url">
jdbc:mysql://localhost/abusefinder
</property>
<property name="hibernate.connection.username">
root
</property>
<property name="hibernate.connection.password">
</property>
<!-- List of XML mapping files -->
<mapping resource="UserDataFromDb.hbm.xml" />
</session-factory>
</hibernate-configuration>
mapping:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="UserDataFromDb" table="user_history">
<id name="id" type="int" column="id">
<generator class="native"/>
</id>
<list name="operations" cascade="all">
<key column="user_id"/>
<list-index column="idx"/>
<one-to-many class="Operation"/>
</list>
<property name="maxOpersPerWeek" column="max_opers_per_week" type="int"/>
<property name="currentOpersPerWeek" column="current_opers_per_week" type="int"/>
<property name="lastWeekFirstOperationTime" column="last_week_first_operation_time" type="long"/>
<property name="addTotal" column="add_total" type="long"/>
<property name="getTotal" column="get_total" type="long"/>
<property name="addOpers" column="add_opers" type="int"/>
<property name="getOpers" column="get_opers" type="int"/>
</class>
<class name="Operation" table="operations">
<id name="operId" type="int" column="oper_id">
<generator class="native"/>
</id>
<property name="userId" column="user_id" type="int"/>
<property name="sum" column="sum" type="long"/>
<property name="time" column="time" type="long"/>
<property name="type" column="type">
<type name="org.hibernate.type.EnumType">
<param name="enumClass">databaseaccess.Type</param>
<param name="useNamed">true</param>
</type>
</property>
</class>
</hibernate-mapping>
Project -> clean
project -> build

Mapping Exception in hibernate

I'm trying to implement one-to-one association mapping but it gives MappingException
Student.hbm.xml file:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 16 Nov, 2012 3:10:16 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="com.sst.student.Student" table="STUDENT">
<id name="studentId" type="java.lang.Long">
<column name="STUDENT_ID" />
<generator class="native" />
</id>
<property name="studentName" type="string" length="20" column="STUDENT_NAME"/>
<many-to-one name="studentAddress"
column="STUDENT_ADDRESS" class="com.sst.student.Address" cascade="all"
unique="true"/>
</class>
</hibernate-mapping>
my Address.hbm.xml file:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 16 Nov, 2012 3:10:16 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="com.sst.student.Address" table="ADDRESS">
<id name="addressId" type="java.lang.Long">
<column name="ADDRESS_ID" />
<generator class="native" />
</id>
<property name="street" type="string" column="STREET" length="20"/>
<property name="city" type="string" column="CITY" length="20"/>
<property name="state" type="string" column="STATE" length="20"/>
<property name="country" type="string" column="COUNTRY" length="20"/>
</class>
</hibernate-mapping>
at the time of code generation I'm getting the following exception:
org.hibernate.MappingException: An association from the table STUDENT refers to an
unmapped class: com.sst.student.Address
my cfg file "one2one.cfg.xml":
<?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.password">root$12</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306
/mysql</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<mapping resource="com/sst/student/Student.hbm.xml"/>
<mapping resource="com/sst/student/Address.hbm.xml"/>
</session-factory>
</hibernate-configuration>
You need a one-to-many mapping in Address hbm.xml.

Categories