データベースに保存する必要があるStudent
オブジェクトがあります。id :studentId
は HBM のように定義されています :-
<id name="studentId" type="long">
<column name="ST_ID" />
<generator class="native" />
</id>
さて、IDを生成するために、以下のように、休止状態のソースに存在していたのと同じように、一般的に実装したコードを書きました:-
// fetching the entity persister for the entity
EntityPersister persister =
((SessionImpl)session.).getEntityPersister(entity.getClass().getName(), entity);
// get the model
PersistentClass model = configuration.getClassMapping(persister.getEntityName());
// cache concurrency
CacheConcurrencyStrategy strategy = persister.getCache();
Class persiterClass = model.getEntityPersisterClass();
SessionFactoryImpl sessionFactoryImpl =
(SessionFactoryImpl) session.getSessionFactory();
if(persiterClass == null) {
persister = new SingleTableEntityPersister(model, strategy, sessionFactoryImpl)
}
this.id = persister.getIdentifierGenerator().generate((SessionImpl)session, entity);
persister.setIdentifier(entity, id, EntityMode.POJO);
今、コード行persister.setIdentifier(entity, id, EntityMode.POJO);
に到達すると、次の例外が発生します:-
IllegalArgumentException in class:
com.school.class.Student, setter method of property: studentId
org.hibernate.property.BasicPropertyAccessor$BasicSetter set
SEVERE: expected type: long, actual value: org.hibernate.id.IdentifierGeneratorFactory$2
org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of com.school.class.Student.studentId
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:104)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.setIdentifier(AbstractEntityTuplizer.java:211)
at org.hibernate.persister.entity.AbstractEntityPersister.setIdentifier(AbstractEntityPersister.java:3601)
at com.school.class.Student.<init>(Student.java:140)
休止状態から同じコードを選択したため、エラーを理解できないため、助けてください。あちらでも正しく動作する場合、このコードはここでも動作するはずです。
ありがとう