3
votes

I have a JPA entity that has child collections via OneToMany relationships and I have set cascade=CascadeType.ALL however when I save the parent entity it does not save any changes done to the child collection (i.e adds or removes) , I have no idea why this is.

It would be useful to know if there was a way to get any information from JPA EntityManager etc about what will be saved at the end of the transaction.

Not sure how to do this? Debugging this has become impossible.

1
Have you set the owning site, with "mappedBy"?niels
Usually this is either incorrect mapping or you haven't added the child to the list of children on the parent correctly.Damo
to check what's your entity's state before persist you might want to have a look EntityListeners docs.oracle.com/html/E24396_01/ejb3_overview_pc_callbacks.htmlKorgen

1 Answers

5
votes

One solution to see what is happening at a SQL level is to turn on debugging on hibernate. If you add a log4j.properties file to your /conf directory, you can manually control the hibernate log output. Here is a sample config file you can use. Uncomment the appropriate areas to turn up log levels:

log4j.logger.org.hibernate=info
### log just the SQL
log4j.logger.org.hibernate.SQL=debug

### log JDBC bind parameters ###
log4j.logger.org.hibernate.type=debug

### log schema export/update ###
log4j.logger.org.hibernate.tool.hbm2ddl=info

### log HQL parse trees
#log4j.logger.org.hibernate.hql=debug