vardeep kaur wrote:Hi
I am getting org.hibernate.MappingException: Unknown entity error
I have class named "FirstExample". Its code is as follows:
[color=cyan]package com;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class FirstExample {
public static void main(String[] args) {
Session session = null;
try {
// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
System.out.println("session is connected " + session.isConnected());
//Create new instance of Contact and set values in it by reading them from form object
System.out.println("Inserting Record");
Contact contact = new Contact();
contact.setId(2);
contact.setFirstName("Raj");
contact.setLastName("S");
contact.setEmail("[email protected]");
session.save(contact);
System.out.println("Done");
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
} finally {
// Actual contact insertion will happen at this step
session.flush();
session.close();
}
}
}[/color]
The Code of hibernate.cfg.xml is as follows:
<?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://10.10.10.19:3306/test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">independent</property>
<!-- Mapping files -->
<mapping package="com"/>
<mapping class="com.Contact"/>
</session-factory>
</hibernate-configuration>
Can you please tell me where is the problem?
vardeep kaur wrote:
<mapping package="com"/>
<mapping class="com.Contact"/>
Cfg.xml and mapping file are in the same default package.
Package of my POJO class is "com"
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|