Hibernate4.1.1.Finalの使用。
@ManyToOneを追加しようとすると、スキーマの作成が次のように失敗します:org.hibernate.MappingException:永続化機能をインスタンス化できませんでしたorg.hibernate.persister.entity.SingleTableEntityPersister
User.java:
@Entity
public class User {
@Id
private int id;
public int getId() {return id;}
public void setId(int id) {this.id = id;}
@ManyToOne
Department department;
public Department getDepartment() {return department;}
public void setDepartment(Department department) {this.department = department;}
}
Department.java
@Entity
public class Department {
@Id
private int departmentNumber;
public int getDepartmentNumber() {return departmentNumber;}
public void setDepartmentNumber(int departmentNumber) {this.departmentNumber = departmentNumber;}
}
hibernate.properties:
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.url=jdbc:mysql://localhost:3306/dbname
hibernate.connection.username=user
hibernate.connection.password=pass
hibernate.connection.pool_size=5
hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
hibernate.hbm2ddl.auto=create
init(例外をスローする):
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().buildServiceRegistry();
sessionFactory = new MetadataSources(
serviceRegistrY.addAnnotatedClass(Department.class).addAnnotatedClass(User.class).buildMetadata().buildSessionFactory();
initでスローされた例外:
org.hibernate.MappingException: Could not instantiate persister org.hibernate.persister.entity.SingleTableEntityPersister
at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:174)
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:148)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:820)
at org.hibernate.metamodel.source.internal.SessionFactoryBuilderImpl.buildSessionFactory(SessionFactoryBuilderImpl.java:65)
at org.hibernate.metamodel.source.internal.MetadataImpl.buildSessionFactory(MetadataImpl.java:340)
他の注釈を追加しようとしましたが、デフォルトが機能してテーブルと外部キーを作成するべきではありませんか?ユーザーから部門を削除すると、テーブルは正常に生成されます。
前もって感謝します!