1
この質問はMappingExceptionの同じトピックに関する他の質問は異なっているorg.hibernate.MappingException:不明なエンティティ
<mapping class="bbb.Students" />
私のエンティティクラスのようにあります次のようになります。
package bbb;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "Students")
public class Students implements java.io.Serializable {
private String id;
private String name;
private String number;
@Id
@Column(name = "ID", unique = true, nullable = false)
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@Column(name = "NAME", nullable = false)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Column(name = "NUMBER", nullable = false)
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
}
私はデータベーステストと生徒用テーブルを手動で作成しました。
エラーは次のとおりです。
org.hibernate.MappingException: Unknown entity: bbb.Students
Exception in thread "main" org.hibernate.MappingException: Unknown entity: bbb.Students
at org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:776)
at org.hibernate.internal.SessionImpl.getEntityPersister(SessionImpl.java:1533)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:104)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:192)
at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:38)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:177)
at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:32)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:73)
at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:682)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:674)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:669)
at bbb.App.main(App.java:39)
次のようにメインクラスがある:
package bbb;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
public class App
{
public static void main(String[] args)
{
System.out.println("Hibernate one to one (Annotation)");
Configuration conf = new Configuration();
SessionFactory sf = conf.configure()
.buildSessionFactory(
new StandardServiceRegistryBuilder()
.applySettings(conf.getProperties())
.build());
Session session = sf.openSession();
session.beginTransaction();
Students s = new Students();
s.setId("1");
s.setName("Joe");
s.setNumber("12345");
session.save(s);
session.getTransaction().commit();
System.out.println("Done");
}
}
次のようにフルhibernate.configがある:
<?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>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<mapping class="bbb.Students" />
</session-factory>
</hibernate-configuration>
私のメインクラスを投稿しました。 – alecrosic