-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Exception in thread "main" org.hibernate.MappingException: U
PostPosted: Sun Sep 22, 2013 12:36 am 
Newbie

Joined: Sun Sep 22, 2013 12:28 am
Posts: 1
My code is given below:

package main.java;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class EmployeeDetails {

/**
* @param args
*/
public static void main(String[] args) {
Employee employee = new Employee();
employee.setEmployeeId(1);
employee.setEmployeeName("First Employee");

SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
session.save(employee);
session.getTransaction().commit();
session.close();
}

}


//This is my pojo

package main.java;

public class Employee {

private int employeeId;
private String employeeName;

public int getEmployeeId() {
return employeeId;
}
public void setEmployeeId(int employeeId) {
this.employeeId = employeeId;
}
public String getEmployeeName() {
return employeeName;
}
public void setEmployeeName(String employeeName) {
this.employeeName = employeeName;
}

}


//This is my hibernate.cfg.xml


<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/test</property>
<property name="connection.username">****</property>
<property name="connection.password">********</property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>

<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>

<!--Names the annotated entity class -->

<mapping class = "main.java.Employee" />
</session-factory>

</hibernate-configuration>


when i am trying to run this code i am getting the following error:

Exception in thread "main" org.hibernate.MappingException: Unknown entity: main.java.Employee
at org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:1141)
at org.hibernate.internal.SessionImpl.getEntityPersister(SessionImpl.java:1433)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:116)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:206)
at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:191)
at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:764)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:756)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:752)
at main.java.EmployeeDetails.main(EmployeeDetails.java:20)



can Any on eplease help me solve this error?

THanks in advance,
hibnatePassion


Top
 Profile  
 
 Post subject: Re: Exception in thread "main" org.hibernate.MappingException: U
PostPosted: Fri Feb 13, 2015 12:07 pm 
Newbie

Joined: Fri Feb 13, 2015 12:03 pm
Posts: 1
In my case it had nothing to do with the actual code. The user I used (root) had no rights on the database. I created a new user with the correct rights and everything worked for me.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.