Hi Andrus,
here there's the code that I use to save my object:
private AtomicReference<DataContext> context = new
AtomicReference<DataContext>(config.getDomain("PacketDomain").createDataContext());
public Network GetNetworkByPK(Integer pkID) {
ObjectId id = new ObjectId(Network.class.getSimpleName(),
Network.ID_PK_COLUMN, pkID);
// this constructor implicitly uses "CACHE_REFRESH" policy, so
a fresh
object will be returned
ObjectIdQuery query = new ObjectIdQuery(id);
return (Network)DataObjectUtils.objectForQuery(context.get(),
query);
}
public PhysicalNode GetPhysicalNodeByMac(byte[] macAddr){
Expression qualifier =
ExpressionFactory.matchExp(PhysicalNode.MAC_ADDRESS_PROPERTY, macAddr);
List<PhysicalNode> list = query(qualifier, PhysicalNode.class);
//there can be only a single result from this query:
return list.get(0);
}
public synchronized PhysicalNode AddPhysicalNode(byte[] macAddr, byte[]
nsap, int netId, short type,
boolean isOnline, String defaultLabel){
PhysicalNode pn=null;
Network n = GetNetworkByPK(netId);
if(n!=null){
pn = GetPhysicalNodeByMac(macAddr);
if(pn==null){
pn = createNewObj(PhysicalNode.class);
pn.setMacAddress(macAddr);
pn.setLabel(defaultLabel);
pn.setCoordX((double)-1);
pn.setCoordY((double)-1);
pn.setCoordZ((double)-1);
pn.setCreation((new Date()).getTime());
}
pn.setNetwork(n);
pn.setNsap(nsap);
pn.setType(type);
pn.setIsOnline(isOnline);
CommitObjects(PhysicalNode.class);
}
else{
throw new ValidationException("Network not in DB");
}
return pn;
}
The problem is not systematic, but may occur with randomness if I force the
DB to add a great number of PhysicalNode objects in a little time window.
Please, let me know if you have any idea!
Thank you very much
Best
cghersi
--
View this message in context:
http://cayenne.195.n3.nabble.com/Temporary-ID-hasn-t-been-replaced-on-commit-tp3801043p3806195.html
Sent from the Cayenne - User mailing list archive at Nabble.com.