users@glassfish.java.net

Cannot persist detached object

From: <glassfish_at_javadesktop.org>
Date: Mon, 26 Feb 2007 13:15:18 PST

I have the following tables:<br />
<br />
Day_Styles<br />
&nbsp; id<br />
&nbsp; name<br />

<br />
Day_Style_Assignments<br />
&nbsp; id<br />
&nbsp; day_style_id<br />
&nbsp; event_id<br />
<br />
Events<br />
&nbsp; name<br />

&nbsp; location (can be null)<br />
&nbsp; booking_type_id (can be null)<br />
&nbsp; age_restricton (can be null)<br />
<br />
<br />
My models look like this:<br />
<br />
public class DayStyles implements Serializable {<br />
<br />

&nbsp; &nbsp; @Id<br />
&nbsp; &nbsp; @Column(name = &quot;id&quot;, nullable = false)<br />
&nbsp; &nbsp; private Integer id;<br />
<br />
&nbsp; &nbsp; @Column(name = &quot;name&quot;, nullable = false)<br />

&nbsp; &nbsp; private String name;<br />
<br />
&nbsp; &nbsp; @ManyToOne(fetch = FetchType.EAGER,cascade = CascadeType.ALL )<br />
&nbsp; &nbsp; @JoinColumn(name=&quot;id&quot;,referencedColumnName=&quot;itinerary_day_style_id&quot;, nullable = <br />

false, insertable=false, updatable=false)<br />
&nbsp; &nbsp; private ItineraryDayStyleAssignments itineraryDayStyleAssignment;<br />
<br />
&nbsp; &nbsp; @OneToMany(mappedBy = &quot;dayStyle&quot;,fetch = FetchType.EAGER, cascade = CascadeType.ALL )<br />
&nbsp; &nbsp; private Collection&lt;DayStyleAssignments&gt; dayStyleAssignments;<br />

&nbsp; &nbsp; .......................<br />
<br />
<br />
public class DayStyleAssignments implements Serializable {<br />
<br />
&nbsp; &nbsp; @Id<br />
&nbsp; &nbsp; @Column(name = &quot;id&quot;, nullable = false)<br />

&nbsp; &nbsp; private Integer id;<br />
<br />
&nbsp; &nbsp; @Column(name = &quot;day_style_id&quot;, nullable = false)<br />
&nbsp; &nbsp; private int dayStyleId;<br />
<br />
&nbsp; &nbsp; @Column(name = &quot;event_id&quot;,nullable = false, insertable=false, updatable=false)<br />

&nbsp; &nbsp; private int eventId;<br />
<br />
&nbsp; &nbsp; @ManyToOne(fetch = FetchType.EAGER,cascade = CascadeType.ALL )<br />
&nbsp; &nbsp; @JoinColumn(name=&quot;day_style_id&quot;,referencedColumnName=&quot;id&quot;, nullable = false, <br />

insertable=false, updatable=false)<br />
&nbsp; &nbsp; private DayStyles dayStyle;<br />
<br />
&nbsp; &nbsp; @ManyToOne(fetch = FetchType.EAGER,cascade = CascadeType.ALL )<br />
&nbsp; &nbsp; @JoinColumn(name=&quot;event_id&quot;,referencedColumnName=&quot;id&quot;)<br />

&nbsp; &nbsp; private Events event;<br />
<br />
&nbsp; &nbsp; @OneToMany(mappedBy = &quot;dayStyleAssignment&quot;,fetch = FetchType.EAGER, cascade = <br />
CascadeType.ALL )<br />
&nbsp; &nbsp; private Collection&lt;Events&gt; events;<br />

&nbsp; &nbsp; ...........................<br />
<br />
public class Events implements Serializable {<br />
<br />
&nbsp; &nbsp; @Id<br />
&nbsp; &nbsp; @Column(name = &quot;id&quot;, nullable = false)<br />

&nbsp; &nbsp; private Integer id;<br />
<br />
&nbsp; &nbsp; @Column(name = &quot;name&quot;, nullable = false)<br />
&nbsp; &nbsp; private String name;<br />
<br />
&nbsp; &nbsp; @OneToMany(mappedBy = &quot;event&quot;,fetch = FetchType.EAGER, cascade = CascadeType.ALL )<br />

&nbsp; &nbsp; private Collection&lt;EventDays&gt; eventDays;<br />
<br />
&nbsp; &nbsp; @OneToMany(mappedBy = &quot;event&quot;,fetch = FetchType.EAGER, cascade = CascadeType.ALL )<br />
&nbsp; &nbsp; private Collection&lt;EventDates&gt; eventDates;<br />

<br />
&nbsp; &nbsp; @OneToMany(mappedBy = &quot;event&quot;,fetch = FetchType.EAGER, cascade = CascadeType.ALL )<br />
&nbsp; &nbsp; private Collection&lt;DayStyleAssignments&gt; dayStyleAssignments;<br />
<br />
&nbsp; &nbsp; @ManyToOne(fetch = FetchType.EAGER,cascade = CascadeType.ALL )<br />

&nbsp; &nbsp; @JoinColumn(name=&quot;id&quot;,referencedColumnName=&quot;event_id&quot;, nullable = false, <br />
insertable=false, updatable=false)<br />
&nbsp; &nbsp; private DayStyleAssignments dayStyleAssignment;<br />
&nbsp; &nbsp; ..............................<br />

<br />
<br />
My JSF page to create a new DayStyleAssignment looks like this :<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;f:view&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;h:messages errorStyle=&quot;color: red&quot; infoStyle=&quot;color: green&quot; layout=&quot;table&quot;/&gt;<br />

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;h1&gt;Add Day Style Event&lt;/h1&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;h:form&gt;<br />

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;h:panelGrid columns=&quot;2"><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;h:outputText value=&quot;Event:&quot; <br />

rendered=&quot;#{dayStyleAssignments.dayStyleAssignments.event == null}&quot;/&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;h:selectOneMenu id=&quot;event&quot; <br />

value=&quot;#{dayStyleAssignments.dayStyleAssignments.event}" title="Event&quot; <br />
rendered=&quot;#{dayStyleAssignments.dayStyleAssignments.event == null}"><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;f:selectItems value=&quot;#{dayStyleAssignments.events}&quot;/&gt;<br />

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/h:selectOneMenu&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/h:panelGrid&gt;<br />

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;h:commandLink action=&quot;#{dayStyleAssignments.create}&quot; value=&quot;Create&quot; <br />
rendered=&quot;#{dayStyleAssignments.dayStyleAssignments.event == null}&quot;/&gt;<br />

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/h:form&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/f:view&gt;<br />
<br />
<br />
dayStyleAssignments is a session bean that maps to a DayStyleAssignmentController.&nbsp; The <br />

DayStyleAssignmentsController has an instance of the entity model DayStyleAssignments.<br />
<br />
<br />
Whenever my dayStyleAssignments.create function is called, I receive the following error.<br />
&nbsp; Exception Description: Cannot persist detached object [Aerobics]. Class&gt; <br />
net.nanonation.rccl.model.Events Primary Key&gt; [4]<br />
<br />
<br />
Can anyone provide any insight?&nbsp; Thanks in advance.<br />

<br />
Jim
[Message sent by forum member 'aantix' (aantix)]

http://forums.java.net/jive/thread.jspa?messageID=205330