This week's book giveaway is in the Android forum.
We're giving away four copies of Learning Java by Building Android Games and have Jean-Marcel Belmont on-line!
See this thread for details.
Win a copy of Learning Java by Building Android Games this week in the Android forum!

Philippe Ponceblanc

Ranch Hand
+ Follow
since Aug 03, 2015
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
0
Total given
26
Given in last 30 days
3
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Philippe Ponceblanc


it misses this code


to initialize RouteId
but I do not know where to put it?
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?
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

Dave Tolls wrote:Airline and Airport use ints for their ids.
Your RouteId class uses Long.

That's why JPA is complaining about:
The type of the ID mapped by the relationship 'source' does not agree with the primary key class of the target entity.



thanks you!

Post/thread Solved
I think I have understood a little, except that I have three errors left, the purpose of which I do not understand.


>> Class Route




>> Class Airline



>> Class Airport



>> Class RouteId

Dave Tolls wrote:For the first one, I think this was mentioned earlier.
The class cannot be final as JPA/Hibernate needs to be able to extend the class as part of how it handles persistence.

The next says exactly what the issue is (again, I think this was brought up earlier).  You need valid equals and hashcode methods.

The following three imply that the primary keys for those classes are not Long, which is what you are using in the RouteId class.
The fields have to match.




1/ RouteId Class == OK

2/ i put valid equals and hashcode methods === OK

3/ yet the errors that i don't anderstand in Route Class == ???
    I do not repeat the mistakes but I must also assimilate, otherwise it is useless, if I do not understand what I code.
    Nothing is going to be an example with my code so that I understand a good time, that will serve me as reference code!






Dave Tolls wrote:What errors are you getting?
(Note that the RouteId is supposed to have getters and setters)





Errors are annotated in green writing with error !


Class RouteId :



Class Route :

I admit that I have trouble following, now I have multiple mistakes which I know what to do to solve them.

Here's my code, I hope I'm not wrong:

>> Class Route



>> Class RouteId



if you have URL link to give me to understand I want, because this way of coding comes out of the course !

Regards
Philippe
Hello,
it seems to me that the solution is in the following link:

https://translate.googleusercontent.com/translate_c?depth=1&hl=fr&prev=search&rurl=translate.google.fr&sl=en&sp=nmt4&u=https://stackoverflow.com/questions/12106124/eclipse-error-on-mapping-with-embeddedid/26540478&xid=17259,15700022,15700124,15700149,15700186,15700190,15700201,15700214&usg=ALkJrhhzOhaLrScUn08Avq9yMriYEEAkLw

I do not understand everything but I use JPA version 2.1, I do not know the specification of the latter, but there is a way around the problem.

Add that the English language is not my mother tongue and I have trouble translating!

could anyone help me?
thanks

Just one problem are in this code,
the @Embeddable = i don't know and generate error == The Java class for mapped type "flights.RouteId" is final

Hello,
I have a class that is annotated by several @Id, it makes me an error on the @Entity of this class.

How can I remove this error?


i restart my server and all it"s work !

Post/Thread SOLVED
i forgot to annotate :


and now the debug of hibernate says me

Caused by: java.lang.IllegalStateException: The file is locked: nio:/home/phipo/.m2/repository/com/h2database/h2/1.4.196/db.mv.db [1.4.196/7]



WHY my database are loked ???
this is my code of error hibernate >>  Could not determine type for: java.util.List, at table: Author, for columns: [org.hibernate.mapping.Column(authors)]


i found the username without password !

here this is my file persistence.xml :



now i have a new error on my table and i don't anderstand !