This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

org.hibernate.HibernateException: problem parsing configuration/hibernate.cfg.xml

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i got this code online..bt its giving me this exception.please help

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:1291)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1230)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1216)
at com.mycompany.ContactManager.main(ContactManager.java:21)
Caused by: org.dom4j.DocumentException: www.hibernate.org Nested exception: www.hibernate.org
at org.dom4j.io.SAXReader.read(SAXReader.java:353)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1286)
... 3 more




here's my code

Hibernate configuration file:

<?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="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/hibernate_ex</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<mapping resource="com/mycompany/Contact.hbm.xml"></mapping>
</session-factory>
</hibernate-configuration>

package com.mycompany;

public class Contact {
private int id;
private String name;
private String email;
private String address;
private String telephone;

public Contact() {

}

public Contact(int id, String name, String email, String address,
String telephone) {
this.id = id;
this.name = name;
this.email = email;
this.address = address;
this.telephone = telephone;
}

public Contact(String name, String email, String address, String telephone) {
this.name = name;
this.email = email;
this.address = address;
this.telephone = telephone;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

public String getTelephone() {
return telephone;
}

public void setTelephone(String telephone) {
this.telephone = telephone;
}
}


<?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="com.mycompany">

<class name="Contact" table="CONTACT">
<id name="id" column="CONTACT_ID">
<generator class="increment"/>
</id>
<property name="name" type="string" column="NAME"/>
<property name="email"/>
<property name="address"/>
<property name="telephone"/>

</class>


 
Nidhi Bansal
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the remaining code:

</hibernare-maping>

Contact Manager class

package com.mycompany;

import java.io.Serializable;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;

/**
* A sample program that demonstrates how to perform simple CRUD operations
* with Hibernate framework.
* @author www.codejava.net
*
*/
public class ContactManager {

public static void main(String[] args) {
// loads configuration and creates a session factory
Configuration configuration = new Configuration().configure();
ServiceRegistryBuilder registry = new ServiceRegistryBuilder();
registry.applySettings(configuration.getProperties());
ServiceRegistry serviceRegistry = registry.buildServiceRegistry();
SessionFactory sessionFactory = configuration.buildSessionFactory();

// opens a new session from the session factory
Session session = sessionFactory.openSession();
session.beginTransaction();

// persists two new Contact objects
Contact contact1 = new Contact("Nam", "hainatu@gmail.com", "Vietnam", "0904277091");
session.persist(contact1);

Contact contact2 = new Contact("Bill", "bill@gmail.com", "USA", "18001900");
Serializable id = session.save(contact2);
System.out.println("created id: " + id);

// loads a new object from database
Contact contact3 = (Contact) session.get(Contact.class, new Integer(1));
if (contact3 == null) {
System.out.println("There is no Contact object with id=1");
} else {
System.out.println("Contact3's name: " + contact3.getName());
}

// loads an object which is assumed exists
Contact contact4 = (Contact) session.load(Contact.class, new Integer(4));
System.out.println("Contact4's name: " + contact4.getName());

// updates a loaded instance of a Contact object
Contact contact5 = (Contact) session.load(Contact.class, new Integer(5));
contact5.setEmail("info1@company.com");
contact5.setTelephone("1234567890");
session.update(contact5);

// updates a detached instance of a Contact object
Contact contact6 = new Contact(3, "Jobs", "jobs@applet.com", "Cupertino", "0123456789");
session.update(contact6);

// deletes an object
Contact contact7 = new Contact();
contact7.setId(7);
session.delete(contact7);

// deletes a loaded instance of an object
Contact contact8 = (Contact) session.load(Contact.class, new Integer(8));
session.delete(contact8);

// commits the transaction and closes the session
session.beginTransaction().commit();
session.close();

}

}
 
Hey cool! They got a blimp! But I have a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic