cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Laurent Marchal <>
Subject Re: 3.0M4 : Fetching from relationship returns TRANSIENT objects.
Date Fri, 19 Sep 2008 09:25:52 GMT
Hi Andrus,

I post on the mailing list with a new mail adress, because my provider 
I will try to detail more what i do, so you can reproduce this in your 
test case. Maybe i'ts because you don't have prefetching or "to dep PK".

There is a relationship between MasterJob--->MasterJobAux where i 
checked "To Dep PK" since no ARTIST_AUX rows can exists without 
corresponding MasterJob.

When i fetch a MasterJob i have added a prefetch for MasterJobAux :


Code I use to get/create/delete MasterJobAux

		protected MasterJobAux createAux(ILookupFieldCodes fieldCode, Short seqNo, String value)
			MasterJobAux aux = MasterJob.this.getObjectContext().newObject(MasterJobAux.class);
			aux.setJaFieldCode((int) fieldCode.getID());

			return aux;

		protected List<MasterJobAux> fetchAuxList() throws OpconException {
			return MasterJob.this.getRelatedMasterJobAux();

		protected void deleteAux(MasterJobAux toDelete) throws OpconException {

Cayenne XML :

	<obj-entity name="MasterJob" className="com.sma.core.api.master.MasterJob" dbEntityName="JMASTER"
		<obj-attribute name="accessCodeId" type="java.lang.Short" db-attribute-path="ACCESSCDID"/>
		<obj-attribute name="altenateMachine1Id" type="java.lang.Short" db-attribute-path="ALTMACH1ID"/>
		<obj-attribute name="altenateMachine2Id" type="java.lang.Short" db-attribute-path="ALTMACH2ID"/>
		<obj-attribute name="altenateMachine3Id" type="java.lang.Short" db-attribute-path="ALTMACH3ID"/>
		<obj-attribute name="deptartmentId" type="java.lang.Short" db-attribute-path="DEPTID"/>
		<obj-attribute name="estimatedRuntime" type="java.lang.Integer" db-attribute-path="ESTRUNTIME"/>
		<obj-attribute name="jobGroupId" type="java.lang.Short" db-attribute-path="JOBGROUPID"/>
		<obj-attribute name="jobName" type="java.lang.String" db-attribute-path="JOBNAME"/>
		<obj-attribute name="jobTypeId" type="java.lang.Short" db-attribute-path="JOBTYPE"/>
		<obj-attribute name="machineGroupId" type="java.lang.Short" db-attribute-path="MACHGRPID"/>
		<obj-attribute name="primaryMachineId" type="java.lang.Short" db-attribute-path="PRIMMACHID"/>
		<obj-attribute name="scheduleId" type="java.lang.Integer" db-attribute-path="SKDID"/>
		<obj-attribute name="shortName" type="java.lang.String" db-attribute-path="SHORTNAME"/>
	<obj-entity name="MasterJobAux" className="com.sma.core.api.auxs.MasterJobAux" dbEntityName="JMASTER_AUX"
		<obj-attribute name="jaFieldCode" type="java.lang.Integer" db-attribute-path="JAFC"/>
		<obj-attribute name="jaSequenceNumber" type="java.lang.Short" db-attribute-path="JASEQNO"/>
		<obj-attribute name="javalue" type="java.lang.String" db-attribute-path="JAVALUE"/>
		<obj-attribute name="jobName" type="java.lang.String" db-attribute-path="JOBNAME"/>
		<obj-attribute name="scheduleId" type="java.lang.Integer" db-attribute-path="SKDID"/>

	<db-relationship name="toMasterJobAux" source="JMASTER" target="JMASTER_AUX" toDependentPK="true"
		<db-attribute-pair source="SKDID" target="SKDID"/>
		<db-attribute-pair source="JOBNAME" target="JOBNAME"/>

	<obj-relationship name="relatedMasterJobAux" source="MasterJob" target="MasterJobAux"

To reproduce the problem :
1) Fetch MasterJobAux  using the relationships


2) delete/create some MasterJobAux


3) Rollback

4) re-Fetch MasterJobAux  using the relationships


I get TRANSIENT objects, you can look a the SQL log attached where there 
is some others details.


Laurent marchal.

> Hi,
> Sorry, you posted this earlier and looks like nobody replied yet.
> So my question is : is this normal to get *TRANSIENT* objects from a 
> relationship after a rollback ?
> No, it is not normal. I just created a test case to reproduce it and 
> things seem to be working ok:
> PaintingInfo info = ctxt.newObject(PaintingInfo.class); 
> info.setTextReview("XXX"); p1.setToPaintingInfo(info);
> assertSame(info, p1.getToPaintingInfo()); ctxt.rollbackChanges(); 
> assertNull(p1.getToPaintingInfo());
> Does it look like the scenario that you have, or am I missing something?
> Thanks, Andrus
> On Sep 15, 2008, at 12:22 PM, Laurent Marchal wrote:
> Hello again !
> I have a strange thing happening in Cayenne 3.0M4 : I have two tables 
> ARTIST and ARTIST_AUX where extended artist's properties are stored.
> There is a relationship between ARTIST--->ARTIST_AUX where i checked 
> "To Dep PK" since no ARTIST_AUX rows can exists without corresponding 
> I have also a addPrefetch(ARTIST_AUX) when i retrieve ARTISTs.
> In my "artist editor" I create ARTIST_AUX rows at need and when an 
> error occurs i do a rollback(). The strange thing is that when i 
> refetch ARTISTS_AUX with the relationship, instead of getting only 
> existing ARTISTS_AUX, i get also the ARTISTS_AUX created before the 
> rollback() with the *TRANSIENT* state and no ObjectContext associated.
> So my question is : is this normal to get *TRANSIENT* objects from a 
> relationship after a rollback ?
> Thanks Laurent Marchal.

View raw message