0

I know that it could be too much vague but what could cause a NullPointerException after adding a @ManyToMany in my jpa entities?

All code is the same, I deleted only the entity linked to the croos table and modified the two entities that before were linked to that entity adding @ManyToMany so the problem isn't the external code or in the db.

The two entities are also linked with a @OneToMany with a second field. Could be this the problem?

This is a structure of my database:

  • table1: id, name, description and table2_id;
  • table2: id, name and description;
  • cross_table: id, table1_id, table2_id and timestamp

Could be a problem the two Set into the entity Table2?

My specs are:

  • java8
  • hibernate5.2
  • jpa2.1
James Z
  • 12,209
  • 10
  • 24
  • 44
Filippo1980
  • 2,745
  • 5
  • 30
  • 44
  • 1
    Jpa doesn't throw any `NullPointerException`, if no elements existed in db jpa will create an empty `Set` for you, maybe you operates on a transient entity and not initializing the `Set`. – holi-java Jul 11 '17 at 17:44
  • @holi-java can you tell me something more? I changed the fetchType from LAZY to EAGER but nothing changed ... – Filippo1980 Jul 13 '17 at 07:35
  • This is the NPE that you don't quote, or give stack trace for. Consequently there is nothing anyone can say. – Neil Stockton Aug 01 '17 at 06:50
  • @Neil Stockton You are right, unfortunally the stackTrace wasn't helpful and I would be generic because, as I wrote on my answer, I was sure that the problem was not the annotation and writing too much it could be confuse! – Filippo1980 Aug 02 '17 at 09:25

1 Answers1

0

As usual, for me, the message caused a misterunderstanding, I thought the problem was @ManyToMany instead the problem was a my error in hibernate.cfg because I removed only the entity table1_table2 and not the mapping annotation on hibernate.cfg! Thank you @holi-java for your hint!

Filippo1980
  • 2,745
  • 5
  • 30
  • 44