У меня есть объект "Событие", и когда я хочу выбрать событие по идентификатору, у меня появляется эта ошибка:
Невозможно установить java.lang.Long Event.idEvent в java.lang.Long
javax.persistence.PersistenceException: org.hibernate.property.access.spi.PropertyAccessException: Error accessing field [private java.lang.Long Event.idEvent] by reflection for persistent property [Event#idEvent] : 1
org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154)
org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:181)
org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1538)
org.hibernate.query.Query.getResultList(Query.java:165)
fr.eni.sortircom.dal.dao.hibernate.HibernateRegistrationDAO.selectById(HibernateRegistrationDAO.java:19)
fr.eni.sortircom.bll.RegistrationManager.selectParticipantEvent(RegistrationManager.java:27)
fr.eni.sortircom.servlet.ShowEventServlet.doGet(ShowEventServlet.java:28)
javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
cause mère
org.hibernate.property.access.spi.PropertyAccessException: Error accessing field [private java.lang.Long fr.eni.sortircom.bo.Event.idEvent] by reflection for persistent property [fr.eni.sortircom.bo.Event#idEvent] : 1
org.hibernate.property.access.spi.GetterFieldImpl.get(GetterFieldImpl.java:75)
org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:224)
org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:4940)
org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:4640)
org.hibernate.engine.internal.ForeignKeys.isTransient(ForeignKeys.java:297)
org.hibernate.engine.internal.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:347)
org.hibernate.type.EntityType.getIdentifier(EntityType.java:495)
org.hibernate.type.EntityType.nullSafeSet(EntityType.java:288)
org.hibernate.param.NamedParameterSpecification.bind(NamedParameterSpecification.java:53)
org.hibernate.loader.hql.QueryLoader.bindParameterValues(QueryLoader.java:645)
org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:2006)
org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1920)
org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1898)
org.hibernate.loader.Loader.doQuery(Loader.java:937)
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:340)
org.hibernate.loader.Loader.doList(Loader.java:2695)
org.hibernate.loader.Loader.doList(Loader.java:2678)
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2512)
org.hibernate.loader.Loader.list(Loader.java:2507)
org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:504)
org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:396)
org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:224)
org.hibernate.internal.SessionImpl.list(SessionImpl.java:1538)
org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1561)
org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1529)
org.hibernate.query.Query.getResultList(Query.java:165)
fr.eni.sortircom.dal.dao.hibernate.HibernateRegistrationDAO.selectById(HibernateRegistrationDAO.java:19)
fr.eni.sortircom.bll.RegistrationManager.selectParticipantEvent(RegistrationManager.java:27)
fr.eni.sortircom.servlet.ShowEventServlet.doGet(ShowEventServlet.java:28)
javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
cause mère
java.lang.IllegalArgumentException: Can not set java.lang.Long field fr.eni.sortircom.bo.Event.idEvent to java.lang.Long
sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:58)
sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:36)
java.lang.reflect.Field.get(Field.java:393)
org.hibernate.property.access.spi.GetterFieldImpl.get(GetterFieldImpl.java:71)
org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:224)
org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:4940)
org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:4640)
org.hibernate.engine.internal.ForeignKeys.isTransient(ForeignKeys.java:297)
org.hibernate.engine.internal.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:347)
org.hibernate.type.EntityType.getIdentifier(EntityType.java:495)
org.hibernate.type.EntityType.nullSafeSet(EntityType.java:288)
org.hibernate.param.NamedParameterSpecification.bind(NamedParameterSpecification.java:53)
org.hibernate.loader.hql.QueryLoader.bindParameterValues(QueryLoader.java:645)
org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:2006)
org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1920)
org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1898)
org.hibernate.loader.Loader.doQuery(Loader.java:937)
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:340)
org.hibernate.loader.Loader.doList(Loader.java:2695)
org.hibernate.loader.Loader.doList(Loader.java:2678)
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2512)
org.hibernate.loader.Loader.list(Loader.java:2507)
org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:504)
org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:396)
org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:224)
org.hibernate.internal.SessionImpl.list(SessionImpl.java:1538)
org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1561)
org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1529)
org.hibernate.query.Query.getResultList(Query.java:165)
fr.eni.sortircom.dal.dao.hibernate.HibernateRegistrationDAO.selectById(HibernateRegistrationDAO.java:19)
fr.eni.sortircom.bll.RegistrationManager.selectParticipantEvent(RegistrationManager.java:27)
fr.eni.sortircom.servlet.ShowEventServlet.doGet(ShowEventServlet.java:28)
javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
вот моя сущность Событие:
public class Event implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_event")
private Long idEvent;
и вот выбор по id:
public Event selectById(Long id) {
Session session = ConnectionProvider.getConnection();
Query q = session.createQuery("FROM Event WHERE idEvent=:id");
q.setParameter("id", id);
List<Event> events = q.getResultList();
Event event = events.get(0);
return event;
}
Я проверил Лонга, и он прав. И у меня есть тот же запрос на другую сущность, и это работает. Я не понимаю.
Спасибо за вашу помощь.