DataContract IsReference only working one way? - silverlight

I have a base class from which all my model classes inherit - Entity. Entity is decorated with
[DataContract(IsReference = true)]
That worked with going from client to server (a save operation). But I'm now getting the same error I was before I added IsReference when going from server to client (a get operation). Any ideas?
Edit:
The error is:
There was an error while trying to
serialize parameter
http://tempuri.org/:GetResult. The
InnerException message was 'Object
graph for type
'Current.Entities.LazyList`1[[Current.Entities.SubPart,
Current.Entities, Version=1.0.0.0,
Culture=neutral,
PublicKeyToken=null]]' contains cycles
and cannot be serialized if reference
tracking is disabled.'. Please see
InnerException for more details.
Edit:
Shoot, I answered this but have since deleted it. I thought I fixed it due to something else I did in the project. I was wrong, this is still causing me an issue. I have a little bit more information - the server-to-client error only happens if an entity in the object graph contains a non-empty LazyList of children. If the list is empty then there's no problem.

Enabling the http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.preserveobjectreferences.aspx flag should fix this. (The flag also exists on DataContractSerializerOperationBehavior -- in config, via the DataContract attribute, and via any custom behaviors you inherit)

Related

How do you specify the SQLite database file in FireDAC's TFDPhysSQLiteDriverLink component?

I'm trying to modify one of the FireDAC sample projects in order to use an existing SQLite file as the database source. The sample works fine unmodified and connects to its database. However, I can't figure out where the database it connects to is specified, in order to change it.
According to the documentation, there should be a Database property on the TFDPhysSQLiteDriverLink component. There isn't: it doesn't exist. I even converted the form to text and looked through all components' customized properties, and there's no path defined anywhere. Nor is there in code - the sample is very small and there's no path defined at all.
The other option on the documentation is to include the FireDAC.Phys.SQLite unit, although that doesn't explain how to set the database, since as far as I can tell that unit just includes the component. And when I search for Database properties (see attached image) none of them in any class in that unit seem to be quite what I'm after. The closest is a string that's for a backup component - I doubt that's what I need. There is a SQLiteDatabase property in the TFDPhysSQLiteConnection class but that's read-only.
List of all Database properties defined in the FireDAC.Phys.SQLite unit
I also tried creating a temporary connection definition at runtime, by double-clicking the TFDConnection component. That only gives an exception:
Exception double-clicking the TFDConnection component
The only solution to this I found is in the XE5 documentation, where it says to set the $(PUBLICDOCUMENTSDIR) environment variable. I already had to do that to get the demo to run (previously, it threw the same exception on the line FDConnection1.Connected := True;; it doesn't now, the demo runs perfectly at runtime.) That change obviously hasn't affected the designer, and I don't even know if I'm looking in the right place, since after all the documentation talks about setting the Database property.
So I'm stumped. Where does it set the database? It's not in the DFM or any streamed properties; it's not in the property defined by the documentation (TFDPhysSQLiteDriverLink.Database doesn't exist, nor does anything that looks like it); it's not in the TFDConnection designtime editor (even though it throws an exception, a file specified as a property here would appear in the streamed DFM, I'd think); it's not in code; ...where else can it be?
(I have never used FireDAC before so am a complete noob, btw. I'm self-teaching via the documentation and samples.)
You don't actually need a TFDPhysSQLiteDriverLink for a minimalist FireDAC project, and using one rather confuses the issue if you're trying to make a connection to a database for the first time.
Try this:
Make a note of the name including path of a Sqlite db.
Start a new VCL project and drop a TFDconnection, TFDQuery, TDataSource & TDBGrid onto its form and connection them up. Set the TDFQuery's Sql to select * from some table you know exists in the db.
Right-click the TFDConnection and select Connection editor from the pop-up.
Set the DriverID to SQLite and insert your db name into the Database Value box.
Open the FDQuery.
If you compile and run the project, you'll get an exception telling you a class factory for a TFDGUIxWaitCursor is missing (this is the sort of thing I love about FireDAC), but that's easily fixed by dropping one onto your form. Notice that you don't have to connect it using the Object Inspector to any of the other FD components.
After that, you can add a TFDPhysSQLiteDriverLink and set its DriverID to the same as for the TFDConnection.
I ussualy roll my own class and handle the OnBeforeConnect event
Something like this
procedure TSQLiteConnection.SQLiteConnectionBeforeConnect(Sender: TObject);
begin
if not(TFile.Exists(DatabaseFilePath)) then
Params.Values['OpenMode'] := 'CreateUTF16'
else
Params.Values['OpenMode'] := 'ReadWrite';
Params.Values['Database'] := DatabaseFilePath;
DriverName := 'SQLite';
end;
The DatabaseFilePath is just a string field of the class, so basically you can put any file path there
TSQLiteConnection is, of course, a TFDConnection descendant

get InvalidSObjectFault [ApiQueryFault [ApiFault exceptionCode='INVALID_TYPE'

Hey I am trying to create some object into salesforce. I have:
SObject myobj = new SObject();
myobj.setType("MyType");
...
But I got:
exceptionMessage='sObject type 'string' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.'
I didn't just put a 'string' there.
Anyone please give some suggestions?
Thanks a lot.
You don't say what you're trying to do by assigning the type, but it looks like you cannot set the type of an sObject in this way. The "string" the error is complaining about is the string "MyType" that you are trying to use to set the type of the sObject.
If you look at the page that describes the methods for sObjects,
http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#CSHID=apex_methods_system_sobject.htm|StartTopic=Content%2Fapex_methods_system_sobject.htm|SkinName=webhelp
you will see that there is no "setType" method, only a "getType" method.
Why do you want to do this ? do you have the type in a variable that you want to use to create an object ?
There is a setType() method when using the Partner API. Is this what you are doing?
In this case you just need to follow the exception message. All custom objects have a API name that end with "__c".
Try
myObj.setType("MyType__c");
The error you see can also happen in a completely different way. I found your question while trying to solve my problem with InvalidSObjectFault. In my case, it was not in how I specified the sObject's type. No. It was permissions. One user (Admin) could run the query but another (my API user) couldn't. Turns out the user's profile needs to have permissions set to see the object. If not then you get this fault message!
Posted more about this on my blog:
http://sforcehacks.blogspot.ca/2013/11/invalidsobjectfault-invalidtype.html

Creating plugin for Django-CMS

I think I screwed up somewhere while trying to create a django-cms plugin and now I am unable to go back. The plugin (called sbbplugin) seems to be "working" (it gets displayed) but whenever I try to publish the site I get the following error:
DatabaseError at /admin/cms/page/18/publish/
relation "cmsplugin_sbbmodel" does not exist
LINE 1: ...id", "cmsplugin_sbbmodel"."cmsplugin_ptr_id" FROM "cmsplugin...
^
I tried removing the plugin but I can not do it because the page is not published. My plugin has no models or anything. Also I'm unable to remove the plugin from the page by clicking delete. Seems like the database is broken. Since I am not experienced enough to know what information you need I would appreciate it, if you could give me further instructions on what I should do.
Update: I think the problem is that I tried to use a model (sbbmodel) which I deleted. Should I try to add the model again? If so what should I do to fix the database? Do I have to run a migration for my app? Do I even have to register the plugin as an app?
Update2: So I tried to add the model again and migrate the app but I get the following error:
CommandError: One or more models did not validate:
sbbplugin.sbbmodel: Accessor for field 'cmsplugin_ptr' clashes with related field 'CMSPlugin.sbbmodel'. Add a related_name argument to the definition for 'cmsplugin_ptr'.
sbbplugin.sbbmodel: Reverse query name for field 'cmsplugin_ptr' clashes with related field 'CMSPlugin.sbbmodel'. Add a related_name argument to the definition for 'cmsplugin_ptr'.
S.sbbmodel: Accessor for field 'cmsplugin_ptr' clashes with related field 'CMSPlugin.sbbmodel'. Add a related_name argument to the definition for 'cmsplugin_ptr'.
S.sbbmodel: Reverse query name for field 'cmsplugin_ptr' clashes with related field 'CMSPlugin.sbbmodel'. Add a related_name argument to the definition for 'cmsplugin_ptr'.
which I do not really understand because I never specified a foreign key. I assume it is because I inherit from CMSPlugin. Any help?
I finally fixed it. First I removed every file that I created for my plugin. Then I deleted every instance of my plugin that was saved in the database. Unfortunately that did not solve the problem and I was still getting the same error even after restarting the server.
What did the trick was to go into phpPgAdmin and select all tables than choose "correct". It did not tell me what exactly the issue was but afterwards everything was back to normal again. So if you somehow run into the same problem, just "correct" your database automatically.

Need elaboration on Unprocessed Continuation Reference

We have a user that our corporate portal cannot fetch the groups for from AD.
On the portal logs we see this error:
javax.naming.PartialResultException: Unprocessed Continuation Reference(s) remaining name ''
I've Googled for the error and the best symptoms that seem to describe this case and how to resolve it are here: http://www-01.ibm.com/support/docview.wss?uid=swg21232921
Assuming we don't want to change the configuration just because of one user but to amend the data of this specific user can someone please explain me how can recognize this when examining the user's record in the AD? Is this something to do with his groups assignments and if yes then what should I look for?
I just ran into this.
I got around it by setting your InitialDirContext environment to have the Context.REFERRAL key set to "follow".
According to the Javadocs, that key can be "follow", "ignore", or "throw". The default is determined by the provider you use, which is probably "throw".
Check out this link for a bit more data on what your API is telling you: http://www.jspwiki.org/wiki/ActiveDirectoryIntegration
I'm not an expert on this API but can explain at least what I think is going on based upon that doc & knowledge of what AD is doing. :)
AD returns what are called "referrals" when you do searches that have naming contexts outside of this local server/search but in the logical scope of your request. This is per RFC request. Think of a referral as a hint to you the app that there might be more data out there...ie, that is, the AD server is saying "here are the results I have for you but, you should know, there is someone else that might have more...go here to find out."
Referrals aren't an "error" they are a hint to the app.
It seems that your LDAP API is throwing an exception when encountering them. Per the docs I referenced above, it looks like you can either swallow them or chase the referral to find out if there is more data.
add this for env properties
env.put(Context.REFERRAL,"follow");
Also one of the issues that i found was that the incorrect search query string in ldapContext. The incorrect query formed due to wrong format of parameter throws:
javax.naming.PartialResultException: Unprocessed Continuation Reference(s) remaining name ''
But if we add the parameter Context.REFERRAL="follow", then it does not throw an exception but neither does it return result.
The parameter to ldap query string should also match the that is being accepted by LDAP else it will throw the same error.

How to choose the test DB cakePHP testing

I am using the cake bake command to create my fixture and Test models. I have done it successfully with one of my models but i am having troubles with another one.
I dont know why, it tries to work with the default DB instead with the test one that i have already defined and that is the one used by the first model i tested.
Both Test models, the one which works well and this 2nd one which doesn't, have been created with cake bake and they look exactly the same.
Both of them have this in their fixture class:
public $import = array('records' => true, 'connection' => 'test');
Test defines the connection to my test database.
What can be the problem?
I have experiment something weird. In my test model if i use the singluar instead of the plural, it works with the default DB BUT if i change it to plural it works with the test DataBase. (but it can not call any method from the model, just defined methods such as find()).
For example:
public function setUp() {
parent::setUp();
//uses the default DB (i dont know why)
$this->Post = ClassRegistry::init('Post');
print_r($this->User->find('all'));
$this->Post->updatePostsStatus(1); //works well
//uses the default Test Database (i dont know why either)
$this->Post = ClassRegistry::init('Posts');
print_r($this->User->find('all'));
$this->Post->updatePostsStatus(1); //doesn't work. No function found.
/*SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'updatePostsStatus' at line 1*/
}
Thanks.
I HAVE UPDATED IT.
LAST UPDATE AND SOLUTION
The problem was the bad initialization of the Post Model constructor.
Using the plural was not relevant. It is like using any non existent model. It will always get the test database.
The answer for the good initialization of the constructor is here:
How to override model's constructor correctly in CakePHP
That sort of MySQL error can be very misleading in CakePHP.
Basically the actual problem is with the line $this->Post->updatePostsStatus(1); Specifically it's that eitherthe Post model or updatePostsStatus() method of the posts model doesn't exist.
You basically have a typo on this line, check the method name. Should it be updatePostStatus? (no plural on posts?)
For some reason, if you try to call an undefined method on a model in CakePHP, instead of reporting the method is not found, the "automagicness" of CakePHP kicks in and bizarrely it tries to push the unfound method name straight into MySQL.
Basically, because CakePHP cannot find the $this->Post->updatePostsStatus(1); method, it is actually trying to execute a MySQL query of updatePostsStatus ie mysql_query("updatePostsStatus');, which is why we are seeing this wierd database error. Chances are you've just misspelled the method name.
If the method name is still not the problem, it's something to do with the Posts model not being instantiated correctly. Although that seems doubtful as long as you got all the names right. It is definitely not a database issue, just Cakes lame way of handling unknown class methods automagically.

Resources