• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

hibernate.PropertyAccessException: Could not set field value [410] value by reflection  RSS feed

 
Ranch Hand
Posts: 200
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I work with the website “openfights.org” I import my data.
I have a persistence “MyApp”, 4 classes: Aireline, Airport, Route and RouteId. I use H2 as a database. I have an ImportData class to import my data from the openfights.org site.
When importing Aireline and Airport data are well filled.
the problem is that for the class Route I had to do a RouteId class because I have several primary keys.
Hibernate raises an exception.

Route class



RouteId class



here is my method of importing Routes



Hibernate Debug :

Hibernate: insert into Airline (active, alias, callsign, country, iata, icao, name, airlineId) values (?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into Airline (active, alias, callsign, country, iata, icao, name, airlineId) values (?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into Airline (active, alias, callsign, country, iata, icao, name, airlineId) values (?, ?, ?, ?, ?, ?, ?, ?)
DEBUG (ImportData.java) - Stream opened to [https://raw.githubusercontent.com/jpatokal/openflights/master/data/routes.dat]
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: Could not set field value [410] value by reflection : [class flights.RouteId.airlineId] setter of flights.RouteId.airlineId
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:147)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:155)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:162)
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:787)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:765)
at ImportData.importFromSource(ImportData.java:199)
at ImportData.main(ImportData.java:230)
Caused by: org.hibernate.PropertyAccessException: Could not set field value [410] value by reflection : [class flights.RouteId.airlineId] setter of flights.RouteId.airlineId
at org.hibernate.property.access.spi.SetterFieldImpl.set(SetterFieldImpl.java:58)
at org.hibernate.mapping.Component$ValueGenerationPlan.execute(Component.java:419)
at org.hibernate.id.CompositeNestedGeneratedValueGenerator.generate(CompositeNestedGeneratedValueGenerator.java:97)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:105)
at org.hibernate.jpa.event.internal.core.JpaPersistEventListener.saveWithGeneratedId(JpaPersistEventListener.java:67)
at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:189)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:132)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:58)
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:780)
... 3 more
Caused by: java.lang.NullPointerException
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:57)
at sun.reflect.UnsafeIntegerFieldAccessorImpl.set(UnsafeIntegerFieldAccessorImpl.java:75)
at java.lang.reflect.Field.set(Field.java:764)
at org.hibernate.property.access.spi.SetterFieldImpl.set(SetterFieldImpl.java:38)
... 11 more

 
Philippe Ponceblanc
Ranch Hand
Posts: 200
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When Route is new, its RouteId id has never been initialized.

How do you see the coding to initialize the RouteId?
what should you do?
 
Philippe Ponceblanc
Ranch Hand
Posts: 200
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

it misses this code


to initialize RouteId
but I do not know where to put it?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!