This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
This may not be a seperate issue, but instead support for issue 172095. If CascadeType.PERSIST is specified, then no exception would be produced. Note that there are cases when CascadeType.ALL is used (which includes PERSIST) so that the current behavior is inconsistent. em.getTransaction().begin(); e = new Event(null, new Date(), 0.0, 0.0, ' ', ' '); e.setEventtypeId(et = new Eventtype(null, "SYS-PreDefinedRules")); Chart chart = new Chart(); chart.setName(AVG_ORB); em.persist(e); em.persist(chart); //em.persist(et); // <<<<<<<<<<<<<< em.getTransaction().commit(); This sequence produced the exception that follows. If the marked/commented line is included, then there is no exception. java.lang.IllegalStateException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST: org.metawb.astro.db.Eventtype[id=null]. javax.persistence.RollbackException: java.lang.IllegalStateException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST: org.metawb.astro.db.Eventtype[id=null]. at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commitInternal(EntityTransactionImpl.java:102) at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commit(EntityTransactionImpl.java:63) at org.metawb.astro.db.PersonTest.makeProfileGroups(PersonTest.java:196) at org.metawb.astro.db.PersonTest.setUp(PersonTest.java:79) Caused by: java.lang.IllegalStateException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST: org.metawb.astro.db.Eventtype[id=null]. at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.discoverAndPersistUnregisteredNewObjects(UnitOfWorkImpl.java:4124) at org.eclipse.persistence.mappings.ObjectReferenceMapping.cascadeDiscoverAndPersistUnregisteredNewObjects(ObjectReferenceMapping.java:801)
I just found: 12.2.1.5 cascade-persist The cascade-persist subelement applies to all relationships in the persistence unit. Specifying this subelement adds the cascade persist option to all relationships in addition to any settings specified in annotations or XML. The cascade-persist subelement may not be overridden in this release. The ability to override the cascade-persist of the persistence-unit-defaults element will be added in a future release of this specification. so as far as I'm concerned you can close this issue. (BTW, I'm beginning to think that CascadeType.ALL should not be used for the auto-gen'd stuff, unless there are user options to turn individual flags on/off. When individual cascades are needed, probably best to include them individually rather than turning everything on.)
Can you provide code for Eventtype, Chart, Event? I see no in 172095. Or schema if entities are generated. Or may be sql script to create tables as schema may not contain necessary all information. Why you do think Cascade.PERSIST should be added in generation? May be another users would like to have more control by default instead of cascade actions. May be I miss something. If it's inconsistent with some similar use case where Cascade.ALL is added, can you provide an example?
looks like project in issue 172943 contain all classes.
even with 172943 project, it's not yet clear what code part is specified above and when CascadeType.ALL is generated when it should not, as I can't find complete sample. Tried to find sql from issue 172943, generate entities for event and chart and both have no cascade specification at all. So if you know more now to describe the problem more clearly, please reopen the issue as I'm not sure what's the issue is. mark as incomplete for now.