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.

Bug 172098 - "Enitty Classes from Database" needs CascadeType.PERSIST
Summary: "Enitty Classes from Database" needs CascadeType.PERSIST
Status: RESOLVED INCOMPLETE
Alias: None
Product: javaee
Classification: Unclassified
Component: Persistence (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: Sergey Petrov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-09-13 03:19 UTC by err
Modified: 2011-03-23 12:51 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description err 2009-09-13 03:19:45 UTC
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)
Comment 1 err 2009-09-17 08:03:21 UTC
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.)
Comment 2 Sergey Petrov 2009-11-03 13:21:55 UTC
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?
Comment 3 Sergey Petrov 2009-11-03 13:38:49 UTC
looks like project in issue 172943 contain all classes.
Comment 4 Sergey Petrov 2011-03-23 12:51:57 UTC
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.