How to prevent a property from being created in a table.

I have a property in my object that just proxies another property, therefore I don’t want a database column created for that property. I tried marking the property with [Transient] metadata but that didn’t help. Is there any other way to accomplish this?

Any thoughts on this? I’ve run into this problem a few times now, and so far I’ve had to convert some properties to methods just to prevent unwanted table columns from being created.

If it can’t be controlled though code or meta-data, it’d be nice if other tables had something similar to the Users table, where you can turn off dynamic fields.

Hi Devin,

We added support for [Transient]. You can apply it either to public fields or public getter functions. Please try with the attached build of the library.

Regards,
Mark

backendless.swc.zip (0.94MB)

Appears to work just fine. Thanks!

I found a situation where this doesn’t quite work.

I have a one-to-many relationship where a WorkoutItem has many Sets. There’s a couple places in the app where I need the inverse relationship (I need to reference the parent WorkoutItem from a Set), so I define that manually… whenever a WorkoutItem’s sets are loaded, I loop the sets and manually give them a reference to the parent WorkoutItem. In the Set class, I’ve marked the workoutItem property as transient.

Whenever I save, I get a stack overflow error. This occurs in the com.backendless.data.store.Utils.addClassName(). Since a WorkoutItem has an array of sets, and each Set references its parent WorkoutItem, it gets into an endless loop.

While debugging this, I see that it retrieves the object’s classInfo (line 100) and that classInfo contains any property metada (including the Transient metadata). So it seems it could use that information to skip the addClassName() method for any properties that are marked as Transient.

Could you please attach some sample code which demonstrates the stack overflow problem?

Hi Devin!

Thank you for this message with description of the problem.
This issue will be fixed in 1.9.1 release (next week).

Regards,
Kate.

Great! I look forward to the next release.

Is v1.9.1 still scheduled to come out soon? I’m still only seeing v1.7 on GitHub.

Hi Devin,

The release has already been deployed. I believe the problem is on the client side in our library. Could you please put together a sample demonstrating the problem and attach it to this thread?

Regards,
Mark

yup, I’m working on the sample right now

Sample project attached

StackOverflow.zip (1.93MB)

This is basically what I’ve had to change in the client library source to get it working for me:

com.backendless.data.store.Utils

around line 70 at the beginning of the for each loop, added:

if (objInfo.metadata[item.localName].hasOwnProperty(“Transient”))
continue;

And then added the same code again to the top of the for each loop around line 106

Hi Devin,

I just pushed changes to the repository with a proper fix for the stack overflow exception you have experienced. You can see the changes in the addClassName function in:

I tried your example with the updated code and it works just fine. Btw, marking recursive properties as Transient may be a bad idea as it might impact the referential consistency in the persistent object state.

I am updating the SDK on the website right now as well.

Regards,
Mark

Thanks. I love the responsiveness and quick reaction from you and the team.

“Btw, marking recursive properties as Transient may be a bad idea as it might impact the referential consistency in the persistent object state.”

That, and it looks like the prepareArgForSend() rebuilds the object, and with the Transient fix, it doesn’t re-attach the recursive property, leaving it null on the client side. So I just need to come up with a different solution anyway.

Please let me know what would be the ideal way to transfer data. Recursive behavior should work (with or without Transient).

Regards,
Mark

It’s very possible that I was trying to do a work-around for something I didn’t need to. In the backendless database, I currently have a one-to-many relationship with WorkoutItem-> Sets. But there’s many places in code that I have a reference to a Set, and need to get it’s WorkoutItem.

Are you saying that I can have a bi-directional relationship? So I can add a many-to-one with Set -> WorkoutItem? If so, that’d be perfect, I just haven’t tried because I thought I read somewhere that it can’t be done.

Yes, you should be able to do that. Please let me know if you run into a problem with that design.

Regards,
Mark

Hi Mark,

I pulled down the latest client library and found your changes. I removed the Transient from the recursive property. The data loaded just fine, but when going to save the object with the recursive property it hit the stackoverflow again. I debugged it and watched hit recurse lines 47 and 85 in the Utils class indefinitely until it crashed.

On an unrelated note, I just discovered the ObjectUtil.getClassInfo() can already take an argument that ignores Transient, as well as read-only properties, which is what I’m primarily using Transient for.

Devin,

If you do not mind, I will use the same sample you send us to debug the issue. I will remove all the Transient attributes to reproduce the problem. Is that okay? (the sample hits your backend).

Regards,
Mark