In general, I decided to master the JPA in annotations and so far it does not work out very well.
I have a class called GenericAd and Image. Image refers to GenericAd @ManyToOne, and in response to Image there is a List @OneToMany. With such a chip, I want to save a new Image from GenericAd to the database, that is, I put a List in GenericAd and when I save / modify it, the new Image is automatically added to the database. This could be done with xml. But here with JPA I suffered, it does not work.
Here is the mapping:
GenericAd:
@Entity @Table public class GenericAd { @Id @GeneratedValue(generator = "increment") @GenericGenerator(name= "increment", strategy= "increment") @Column(length = 6, nullable = false) private long id; @Column(nullable = false) @Type(type="text") private String description; @Column(nullable = false) private String title; @Column(nullable = false) private String dateAdd; @Column private AdType adType; @Column(nullable = false) private String phoneNumberAuthor; @Column(nullable = false) private String city; @Column private String region; @Column private String district; @Column private String price; @Column(nullable = false) private String adLink; @OneToMany(fetch = FetchType.EAGER, mappedBy = "adEntity", cascade = CascadeType.PERSIST) private List<Image> images; Image:
@Entity @Table public class Image { @Id @GeneratedValue(generator = "increment") @GenericGenerator(name= "increment", strategy= "increment") @Column(length = 6, nullable = false) private long id; @Column(nullable = false) private byte[] image; @ManyToOne() @JoinColumn(name = "ad_id") private GenericAd adEntity; Save data via GenericAdDAO using HibernateTemplate 
At the output, I expect the saved GenericAd (genericad) and Image (in the image table) GenericAd is stored normally, but the Image is not, although with a debugger I checked the List <Image> in GenericAd is not empty before saving.
Here is the database:
And the image is empty! 
What could be the problem ?