cascade-update not working in my case


pavansailendra04@...
 

Class log
{
private int id;
@Persistent(column = "userId", defaultFetchGroup = "true")
@Extensions({@Extension(vendorName = "datanucleus", key = "cascade-update", value = "false")})
private User user;
}


Class User {
@Persistent(primaryKey = "true", valueStrategy = IdGeneratorStrategy.IDENTITY)
private int userId;
}

Every log has related user.

When updating or inserting log, we dont want to update user properties .
For example

Log log = new Log();
user.setRegion("CA")
log.set(user);

persist(log);

User region is getting updated even if cascade-update is false. [Cascade-persist is working!!]

Can some one please help on this ?

I debugged the code https://github.com/datanucleus/datanucleus-rdbms/blob/0812934216a04a63e953e173ebf4398250cc8150/src/main/java/org/datanucleus/store/rdbms/mapping/java/PersistableMapping.java#L598 cascade persist check is there but could not find any check for cascade-update. Should we persist data in different way ?


pavansailendra04@...
 

I have debugged and tried adding another field.
Class log
{
private int id;
@Persistent(column = "userId", defaultFetchGroup = "true")
@Extensions({@Extension(vendorName = "datanucleus", key = "cascade-update", value = "false")})
private User[] user;
}

Added user array instead of user. Now the casade-update seems to be working.
https://github.com/datanucleus/datanucleus-rdbms/blob/4.0/src/main/java/org/datanucleus/store/rdbms/mapping/java/ArrayMapping.java#L237
Any specific reason why it is not implemented for normal objects. Implemented for collections, maps and arrays only 


Andy
 

Maybe, since not a core JDO feature, nobody had time to implement it for 1-1 relations. Maybe there was no resource.


pavansailendra04@...
 

Thanks Andy for the confirmation. Can we achieve the same the functionality through any other existing feature?


Andy
 

I didn't "confirm" anything. I simply said maybe it wasn't completed.

Either way, in v6.0 that option is renamed "cascade-attach" since it provides for JPA CascadeType.MERGE (which is basically JDO "attach"). As a result "cascade-persist" will cater for both inserts and updates.