私のオブジェクトを保存したいとき、それは未知のエンティティ例外をスローします。スレッド "メイン" org.hibernate.MappingExceptionでhibernate 5を使用しているときにhibernateの未知のエンティティjava 8
TNX事前に
例外:不明 エンティティ: org.hibernate.metamodel.internal.MetamodelImpl.entityPersisterでcom.simpleProgrammer.User(MetamodelImpl .java:618) でorg.hibernate.internal.SessionImpl.getEntityPersister(SessionImpl.java:1595) でorg.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:104) ORGで。ハイバー org.hibernate.event.internal.DefaultSaveOrUpdateEventListenerでnate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:192) でorg.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:38) 。 org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:73)でentityIsTransient(DefaultSaveOrUpdateEventListener.java:177) でorg.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:32) at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:667) でorg.hibernate.internal.SessionImpl.save(SessionImpl.java:659)で org.hibernate.internal.SessionImpl.save(SessionImpl.java:654)で com.simpleProgrammer.Program.main(Program.java: 22)
私のhibernate.cfg.xmlファイルは、ここで
<?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.cj.jdbc.Driver</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/protein_tracker</property>
<property name="hibernate.connection.username">root</property>
<!-- <property name="hibernate.default_schema"></property> -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<mapping resource="com/simpleProgrammer/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
私User.hbm.xmlマッピングファイル
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping">
<hibernate-mapping>
<class name="com.simpleProgrammer.User" table="USERS">
<id name="id" type="int" column="id">
<generator class="identity" />
</id>
<property name="name" column="NAME" type="string" />
<component name="proteinData">
<property name="total" column="TOTAL" type="int" />
<property name="goal" column="GOAL" type="int" />
</component>
<set name="history" table="USER_HISTORY">
<key column="ID"/>
<composite-element class="com.simpleProgrammer.UserHistory">
<property name="entryTime" type="date" column="ENTRY_TIME"/>
<property name="entry" type="string" column="ENTRY"/>
</composite-element>
</set>
</class>
</hibernate-mapping>
です
私progaram.java
package com.simpleProgrammer;
import java.util.Date;
import org.hibernate.Session;
public class Program {
public static void main(String[] args) {
Session session = new HibernateUtilities().getSessionFactory().openSession();
System.out.println("Session Opened!!!");
session.beginTransaction();
System.out.println("Transaction begined!");
User user = new User();
user.setName("Joe");
user.getHistory().add(new UserHistory(new Date(), "Setting Name to Joe"));
user.getProteinData().setGoal(250);
user.getHistory().add(new UserHistory(new Date(), "Setting Goal to 250!"));
System.out.println("Setting user Object");
session.save(user);
System.out.println("Saving user object on table");
session.getTransaction().commit();
System.out.println("Transaction Commited!");
session.beginTransaction();
User loadedUser = session.get(User.class, 1);
System.out.println(loadedUser.getName());
System.out.println(loadedUser.getProteinData().getGoal());
System.out.println(loadedUser.getProteinData().getTotal());
loadedUser.getProteinData().setTotal(loadedUser.getProteinData().getTotal() + 50);
loadedUser.getHistory().add(new UserHistory(new Date(), "Added 50 Protein!"));
for (UserHistory history : loadedUser.getHistory()) {
System.out.println(history.getEntryTime().toString() + " " + history.getEntry());
}
session.getTransaction().commit();
session.close();
System.out.println("Session Closed!!!");
HibernateUtilities().getSessionFactory().close();
System.out.println("Session Factory Closed");
}
}
ユーザークラス
package com.simpleProgrammer;
import java.util.HashSet;
import java.util.Set;
public class User {
private int id;
private String name;
private ProteinData proteinData = new ProteinData();
private Set<UserHistory> history = new HashSet<UserHistory>();
public Set<UserHistory> getHistory() {
return history;
}
public void setHistory(Set<UserHistory> history) {
this.history = history;
}
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 ProteinData getProteinData() {
return proteinData;
}
public void setProteinData(ProteinData proteinData) {
this.proteinData = proteinData;
}
}
これを試してみてください: http://stackoverflow.com/questions/33194384/exception-in-thread-main-org-hibernate-mappingexception-unknown-entity – zaggi
これは私のために働いてください: [ここにリンクの説明を入力](http://stackoverflow.com/questions/33194384/exception-in-thread-main-org-hibernate-mappingexception-unknown-entity) – zaggi