Exception in thread "main" org.hibernate.InvalidMappingException: Unable to read XML - java

> I am using eclipse .I tried to do java hibernate program for the first time but got the above error.please help me to solve it.
downloaded hibernate release 4.2.5 final.zip and added jar files to user library
antlr-2.7.7.jar
dom4j-1.6.1.jar
hibernate-commons-annotations-4.0.2.Final.jar
hibernate-core-4.2.5.Final.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
javassist-3.15.0-GA.jar
jboss-logging-3.1.0.GA.jar
jboss-transaction-api_1.1_spec-1.0.1.Final.jar
hibernate-entitymanager-4.2.5.Final.jar
hibernate-envers-4.2.5.Final.jar
hibernate-osgi-4.2.5.Final.jar
org.osgi.core-4.3.1.jar
is these jar files enough for hibernate program.
hibernate.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>
<!-- Related to the connection START -->
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver
</property>
<property name="connection.url">jdbc:oracle:thin:#192.168.1.2:1521:xe</property>
<property name="connection.user">system</property>
<property name="connection.password">siddhu</property>
<!-- Related to the connection END -->
<!-- Related to hibernate properties START -->
<property name="show_sql">true</property>
<property name="dialet">org.hibernate.dialect.OracleDialect</property>
<property name="hbm2ddl.auto">update</property>
<!-- Related to hibernate properties END -->
<!-- Related to mapping START -->
<mapping resource="Details.hbm.xml"/>
<!-- Related to the mapping END -->
</session-factory>
</hibernate-configuration>
Details.hbm.xml
- <hibernate-mapping>
- <class name="Details" table="stu">
- <id name="stNo" column="SNo">
<generator class="assigned" />
</id>
<property name="stName" column="SName" />
<property name="stAddress" />
</class>
</hibernate-mapping>
mainclass.java
import org.hibernate.*;
import org.hibernate.cfg.*;
public class mainclass {
public static void main(String[] args)
{
Configuration c = new Configuration();
c.configure("hibernate.cfg.xml");
SessionFactory factory = c.buildSessionFactory();
Session session = factory.openSession();
Details p=new Details();
p.setStno(101);
p.setStName ("iPhone");
p.setStAddress("dfdsgdf");
Transaction tx = session.beginTransaction();
session.save(p);
System.out.println("Object saved successfully.....!!");
tx.commit();
session.close();
factory.close();
}
}
Details.java
public class Details {
private int stNo;
private String stName;
private String stAddress;
public void setStno(int stNo)
{
this.stNo=stNo;
}
public int getStNo()
{
return stNo;
}
public void setStName(String stName)
{
this.stName=stName;
}
public String getStName()
{
return stName;
}
public void setStAddress(String stAddress)
{
this.stAddress=stAddress;
}
public String getStAddress()
{
return stAddress;
}
}
Console Error
===========================================
Sep 20, 2013 6:49:30 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
Sep 20, 2013 6:49:30 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.5.Final}
Sep 20, 2013 6:49:30 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Sep 20, 2013 6:49:30 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Sep 20, 2013 6:49:30 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: hibernate.cfg.xml
Sep 20, 2013 6:49:30 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: hibernate.cfg.xml
Sep 20, 2013 6:49:31 PM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
Sep 20, 2013 6:49:31 PM org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: Details.hbm.xml
Exception in thread "main" org.hibernate.InvalidMappingException: Unable to read XML
at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:109)
at org.hibernate.cfg.Configuration.add(Configuration.java:488)
at org.hibernate.cfg.Configuration.add(Configuration.java:484)
at org.hibernate.cfg.Configuration.add(Configuration.java:657)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:740)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2188)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2160)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2140)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2093)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2008)
at mainclass.main(mainclass.java:9)
Caused by: org.dom4j.DocumentException: Error on line 1 of document : Content is not allowed in prolog. Nested exception: Content is not allowed in prolog.
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:78)
... 10 more

Your XML file, for whatever reason, might contain a BOM as described in this answer and its linked article.
I suggest you create a new file and write (copy) over the configuration from your mapping file.

Related

Hibernate doesnt see path

I have some problems with hibernate. I am sharing my code.
The error I am getting
"C:\Program Files\Java\jdk1.8.0_161\bin\java"
-Dfile.encoding=windows-1250 -jar C:\Users\kubci\IdeaProjects\FinalProject\target\hibernate-1.0-SNAPSHOT-jar-with-dependencies.jar
maj 29, 2018 7:41:56 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {[WORKING]}
maj 29, 2018 7:41:56 PM org.hibernate.cfg.Environment
INFO: HHH000206: hibernate.properties not found
maj 29, 2018 7:41:57 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager
INFO: HCANN000001: Hibernate Commons Annotations {5.0.3.Final}
maj 29, 2018 7:41:58 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl
configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
maj 29, 2018 7:41:58 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl
buildCreator
INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/loginpanel]
maj 29, 2018 7:41:58 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl
buildCreator
INFO: HHH10001001: Connection properties: {user=root, password=****}
maj 29, 2018 7:41:58 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl
buildCreator
INFO: HHH10001003: Autocommit mode: false
maj 29, 2018 7:41:58 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
maj 29, 2018 7:41:58 PM org.hibernate.dialect.Dialect
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
Exception in thread "main" org.hibernate.boot.registry.classloading.spi.ClassLoadingException:
Unable to load class [pl.Final.Project.entities.LoginConnection]
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:354)
at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.(AnnotationMetadataSourceProcessorImpl.java:105)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.(MetadataBuildingProcess.java:156)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:150)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:84)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:474)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:85)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:689)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
at pl.Final.Project.Main.main(Main.java:19)
Caused by: java.lang.ClassNotFoundException: Could not load requested class : pl.Final.Project.entities.LoginConnection
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl$AggregatedClassLoader.findClass(ClassLoaderServiceImpl.java:342)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:351)
... 9 more
This is my Main .
package pl.Final.Project;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import pl.Final.Project.entities.LoginUser;
import javax.security.auth.login.AppConfigurationEntry;
import javax.security.auth.login.Configuration;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class Main {
private static SessionFactory factory;
public static void main(String[] args) {
factory = new org.hibernate.cfg.Configuration().configure().buildSessionFactory();
System.exit(0);
}
public static ArrayList<LoginUser> getUsersList(){
Session session = factory.openSession();
Transaction tx = null;
ArrayList<LoginUser> usersArrayList= new ArrayList<>();
try{
tx = session.beginTransaction();
List customerList = session.createQuery("FROM pl.Final.Project.entities.LoginUser WHERE id=1").list();
for(Iterator iterator = customerList.iterator(); iterator.hasNext();){
LoginUser c =(LoginUser) iterator.next();
usersArrayList.add(c);
}
tx.commit();
}catch (HibernateException e){
if(tx!=null){
tx.rollback();
}
}finally {
session.close();
}
return usersArrayList;
}
}
and cfg.xml and hmb.xml files
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration SYSTEM
"http://hibernate.org/dtd/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://localhost:3306/loginpanel</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<mapping class="pl.Final.Project.entities.LoginConnection" />
</session-factory>
</hibernate-configuration>
<?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 = "pl.Final.Project.entities.LoginUser" table = "tuser">
<meta attribute = "class-description">
Login Customer mapping
</meta>
<id name = "id" type = "int" column = "id">
<generator class="native"/>
</id>
<property name = "login" column = "login" type = "string"/>
<property name = "password" column = "password" type = "string"/>
<property name = "name" column = "name" type = "string"/>
<property name = "surname" column = "surname" type = "string"/>
</class>
</hibernate-mapping>
I don't know what to do. I had another project with this code and it works. I did copy and paste, change some details like path etc. There are some errors and I think here is the problem:
Exception in thread "main"
org.hibernate.boot.registry.classloading.spi.ClassLoadingException:
Unable to load class [pl.Final.Project.entities.LoginConnection]
The exception you encountered says clearly that LoginConnection class can't be loaded. Yet there is no LoginConnection class to be seen. You've added LoginConnection as mapping class for Hibernate session, but source code of LoginConnection is missing. Maybe you should create LoginConnection class first, before it can be loaded?
Or did you accidently write LoginConnection instead of LoginUser?

how to solve "javax.persistence.OptimisticLockException:" in hibernate?

Error:
May 27, 2017 2:39:48 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.0.Final}
May 27, 2017 2:39:48 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
May 27, 2017 2:39:48 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
May 27, 2017 2:39:49 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
May 27, 2017 2:39:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
May 27, 2017 2:39:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3305/db]
May 27, 2017 2:39:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=root, password=****}
May 27, 2017 2:39:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
May 27, 2017 2:39:52 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
May 27, 2017 2:39:52 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
May 27, 2017 2:39:52 PM org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl useContextualLobCreation
INFO: HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
May 27, 2017 2:39:54 PM org.hibernate.internal.ExceptionMapperStandardImpl mapManagedFlushFailure
ERROR: HHH000346: Error during managed flush [Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1]
javax.persistence.OptimisticLockException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
Code:
pojo class
public class Testpojo {
private int number;
private String name;
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
main class
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class TestMain {
/**
* #param args
*/
public static void main(String[] args) {
Testpojo tp=new Testpojo();
tp.setNumber(3);
tp.setName("MEHUL1");
try{
SessionFactory ses=new Configuration().configure().buildSessionFactory();
Session s1=ses.openSession();
Transaction tr=s1.beginTransaction();
s1.update(tp);
tr.commit();
}catch(Exception e){
System.out.println(e);
}
}
}
Configuration file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration SYSTEM
"http://www.hibernate.org/dtd/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:3305/db</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<mapping resource="Testpojo.hbm.xml"/>
</session-factory>
</hibernate-configuration>
mapping file
<?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="Testpojo" table="t">
<id name="number" column="num">
<generator class="native"></generator>
</id>`enter code here`
<property name="name" column="name"></property>
</class>
</hibernate-mapping>
create one simple appliaction of hibernate with Testpojo.java ,Testpojo.hbm.xml,Testmain.java and hibernatecfg.xml.
how to solve "javax.persistence.OptimisticLockException:" in hibernate ?
add all jar file of hibernate but still found this error.javax.persistence.OptimisticLockException:
You got OptimisticLockException means some other transcation is already using that particular record.

Hibernate cant test my session, it's null

Hi im using eclipse this hibernate update.
i have this config:
<?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://localhost:3306</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.default_schema">protein_tracker</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql">true</property>
</session-factory>
</hibernate-configuration>
i have this class that has the basics to start hibernate:
package com.simpleprogramer;
import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.ServiceRegistry;
public class HibernateUtilities {
private static SessionFactory sessionFactory;
private static ServiceRegistry serviceRegistry;
static{
try{
Configuration configuration = new Configuration().configure();
serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
}
catch(HibernateException exeption)
{
System.out.println("Problem creating session factory!");
}
}
public static SessionFactory getSessionFactory(){
return sessionFactory;
}
}
and main that test hibernate session, and i don't know were is the null:
package com.simpleprogramer;
import org.hibernate.Session;
public class program {
public static void main(String[] args) {
System.out.println("Hola mundo");
Session session = HibernateUtilities.getSessionFactory().openSession();
session.close();
}
}
getting this error from console:
Hola mundo
oct 01, 2013 2:12:31 AM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
oct 01, 2013 2:12:31 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.6.Final}
oct 01, 2013 2:12:31 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
oct 01, 2013 2:12:31 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
oct 01, 2013 2:12:31 AM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
oct 01, 2013 2:12:31 AM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
oct 01, 2013 2:12:31 AM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
oct 01, 2013 2:12:31 AM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
oct 01, 2013 2:12:31 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
Problem creating session factory!
Exception in thread "main" java.lang.NullPointerException
at com.simpleprogramer.program.main(program.java:9)
Hi there, thank you for your advice exeption.printStacktrace(System.out);. I figure out that my jdbc driver was not loaded, and then realized that it wasn't loaded at all on the proyect (i thought that the config autoload no matter what or were the driver is). So i downloaded the corresponding jar and it works. Thanks for your advice!

Error: Could not get constructor for org.hibernate.ogm.persister.OgmEntityPersister

I want to write a veriy simple example with HibernateOGM to populate a collection in MongoDB, but if I run my Programm, I get this exception:
Exception in thread "main" org.hibernate.MappingException: Could not get constructor for org.hibernate.ogm.persister.OgmEntityPersister
this is my stack trace:
*at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:185)
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:383)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1750)
at hogm.hibernateogm_mongodb.App.main(App.java:30)*
hier is my POJO:
public class Contact {
#Id
private Long id;
private String email;
private String firstname;
private String lastname;
public String getEmail() {
return email;
}
/**
* #param email the email to set
*/
public void setEmail(String email) {
this.email = email;
}
and here you can find my hibernate.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.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.ogm.datastore.provider">mongodb</property>
<property name="hibernate.ogm.mongodb.database">rcfdb</property>
<property name="hibernate.ogm.mongodb.host">127.0.0.1</property>
<property name="hibernate.ogm.mongodb.port">27017</property>
<mapping resource="hibernate-contact.hbm.xml"/>
</session-factory>
</hibernate-configuration>
and 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="Untersuchungsraum.Contact" table="District">
<id column="id" type="integer" >
<generator class="native">
</generator>
</id>
<property name="firstname" type="java.lang.String">
<column name="Firstname"></column>
</property>
<property name="lastname" type="java.lang.String">
<column name="lastname"></column>
</property>
<property name="email" type="java.lang.String">
<column name="email"></column>
</property>
</class>
</hibernate-mapping>
Do you have may be an Idea to solve this problem? thanks
*UPDATE*
my complete stack trace:
Scanning for projects...
------------------------------------------------------------------------
Building HibernateOGM_MongoDB 1.0-SNAPSHOT
------------------------------------------------------------------------
[resources:resources]
[debug] execute contextualize
Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
Copying 2 resources
[compiler:compile]
File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
Compiling 1 source file to C:\Users\Babak\Documents\NetBeansProjects\HibernateOGM_MongoDB\target\classes
[exec:exec]
Aug 14, 2013 4:16:57 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
Aug 14, 2013 4:16:57 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.9.Final}
Aug 14, 2013 4:16:57 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Aug 14, 2013 4:16:57 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Aug 14, 2013 4:16:57 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: hibernate.cfg.xml
Aug 14, 2013 4:16:57 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: hibernate.cfg.xml
Aug 14, 2013 4:16:57 PM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
Aug 14, 2013 4:16:57 PM org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: hibernate-contact.hbm.xml
Aug 14, 2013 4:16:57 PM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
Aug 14, 2013 4:16:57 PM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
Aug 14, 2013 4:16:57 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.ogm.dialect.NoopDialect
Aug 14, 2013 4:16:57 PM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000422: Disabling contextual LOB creation as connection was null
Aug 14, 2013 4:16:57 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
Aug 14, 2013 4:16:57 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Aug 14, 2013 4:16:57 PM org.hibernate.ogm.cfg.impl.Version <clinit>
INFO: OGM000001: Hibernate OGM 4.0.0.Beta1
Exception in thread "main" org.hibernate.MappingException: Could not get constructor for org.hibernate.ogm.persister.OgmEntityPersister
at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:185)
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:383)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1750)
at hogm.hibernateogm_mongodb.App.main(App.java:30)
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.ogm.datastore.spi.DatastoreProvider]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:186)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:150)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
at org.hibernate.ogm.datastore.impl.DatastoreServicesImpl.configure(DatastoreServicesImpl.java:53)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
at org.hibernate.ogm.persister.OgmEntityPersister.<init>(OgmEntityPersister.java:125)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163)
... 4 more
Caused by: org.hibernate.HibernateException: OGM000008: DatastoreManager class [mongodb] cannot be found in classpath try with: [MAP, INFINISPAN, EHCACHE, MONGODB]
at org.hibernate.ogm.datastore.impl.DatastoreProviderInitiator.buildServiceInstance(DatastoreProviderInitiator.java:64)
at org.hibernate.ogm.datastore.impl.DatastoreProviderInitiator.buildServiceInstance(DatastoreProviderInitiator.java:40)
at org.hibernate.ogm.service.impl.OptionalServiceInitiator.initiateService(OptionalServiceInitiator.java:37)
at org.hibernate.service.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:69)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:176)
... 16 more
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 3.141s
Finished at: Wed Aug 14 16:16:58 PDT 2013
Final Memory: 10M/25M
------------------------------------------------------------------------
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default-cli) on project HibernateOGM_MongoDB: Command execution failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.
For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Do you have something like this in your pom?
<dependency>
<groupId>org.hibernate.ogm</groupId>
<artifactId>hibernate-ogm-mongodb</artifactId>
<version>4.0.0.Beta3</version>
</dependency>
Looks like you don't add jar for MongoDB.

Hibernate exception on 4.0 XSD

First time out of the box with Hibernate, and getting a bizarre error. I am using the 4.2.3 Final version, and would like to use the 4.0 XSD schema, but will use the 3.0 DTD if that's what it takes to get it to work.
My driver:
public static void main(String[] args) {
Configuration configuration = new Configuration();
configuration.configure("hibernate/cfg/hibernate.cfg.xml");
ServiceRegistryBuilder serviceRegistryBuilder = new ServiceRegistryBuilder().applySettings(configuration
.getProperties());
SessionFactory sessionFactory = configuration
.buildSessionFactory(serviceRegistryBuilder.buildServiceRegistry());
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
User user = new User("Dr.", "Sylvester", "McMonkey", "McBean", "IV");
session.save(user);
tx.commit();
session.close();
}
My hibernate.cfg.xml file, located in my project under src/main/config/hibernate/cfg:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-configuration
xmlns="http://www.hibernate.org/xsd/hibernate-configuration"
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-configuration hibernate-configuration-4.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://my-server:3306/my_db</property>
<property name="hibernate.connection.username">myuser</property>
<property name="hibernate.connection.password">password</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="use_sql_comments">true</property>
<property name="hbm2ddl.auto">validate</property>
<mapping resource="User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
And the stacktrace Eclipse is giving me:
Jul 27, 2013 9:10:08 AM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
Jul 27, 2013 9:10:08 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.3.Final}
Jul 27, 2013 9:10:08 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Jul 27, 2013 9:10:08 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Jul 27, 2013 9:10:08 AM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: hibernate/cfg/hibernate.cfg.xml
Jul 27, 2013 9:10:08 AM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: hibernate/cfg/hibernate.cfg.xml
Exception in thread "main" org.hibernate.MappingException: invalid configuration
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2070)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1987)
at com.apponomical.adaptors.datasource.HibernateDriver.main(HibernateDriver.java:15)
Caused by: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 25; Document is invalid: no grammar found.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
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:387)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:321)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:226)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:602)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3080)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:899)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:625)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:116)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:488)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:819)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:748)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1208)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:525)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2067)
... 2 more
Thoughts? Ideas? Suggestions? Thanks in advance!
The validator is not finding the schema. The xsi:schemaLocation attribute tells it to look for schema document hibernate-configuration-4.0.xsd in the same directory as the configuration document you're validating (.../src/main/config/hibernate/cfg). Is that where you have it?
With Hibernate 4.x you should use the same DTD as 3.x as you can see by this bug report, where the deprecation warning was removed.
Also the tutorials for 4.2 version use this, as you can see here.

Categories

Resources