Agile PLM API create relationship between items: Invalid Parameter - oracle

I'm developing an scala application using Agile PLM API.
Everything works so far, adding attachments, adding BOM items, creating items and so on.
But when creating Relationships in the Relationship Table, I always get this error:
com.agile.api.APIException: Invalid parameter.
at com.agile.api.pc.Session.createError(Session.java:2039)
at com.agile.api.pc.APIObject.createError(APIObject.java:76)
at com.agile.api.pc.TableRelationships.convertCreateParamMapToVOCells(TableRelationships.java:92)
at com.agile.api.pc.TablePC.doCreateServerRowWithParam(TablePC.java:58)
at com.agile.api.pc.Table.createTableRow(Table.java:267)
at com.agile.api.pc.Table.createRow(Table.java:231)
The Agile API requires a hashmap with attributes and values as parameter to create the relationship. So this is my code:
val cells: java.utils.Map[_, _] = Map(
Attrs.Items.Relationships.CriteriaMet -> null,
Attrs.Items.Relationships.TypeImage -> 666, // id of item type as Integer
Attrs.Items.Relationships.Name -> "foo", // name as String
Attrs.Items.Relationships.Description -> "bar", // the description as String
Attrs.Items.Relationships.CurrentStatus -> "Production", // lifecyclephase 'Production' as a String
Attrs.Items.Relationships.Rule -> null,
Attrs.Items.Relationships.Type -> 600 // id of item type as Integer
)
relationshipTable.createRow(cells)
The relationshipTable instance is of type ITable and this kind of Map is working for adding BOM items and attachments, so I think this is not the issue here.
I simply queried the cells of existing relationships manually and compared their key with my constants used in this map and they are the same. I really don't know what the invalid parameter is. Is there an attribute missing? Is the type of an parameter wrong? There is no indication what's wrong.

Ok, the answer was quite simple, despite it works different than for the BOM and it is not documented.
The solution is simply passing the iitem you want to add as a relationship:
relationshipTable.createRow(iitem)

Related

How to prevent Child models from Deletion in Golang GORM?

Well, I would like to know, Is there any solutions, how to prevent Child Model from deletion in foreignKey Constraint, (
For example in gorm there is a couple of options that allows to restrict behavior of the Parent Model after deletion, and Delete or Set to Null the Child Model Objects That has foreignKey relation (onDelete: Cascade / Set Null, and the same thing for onUpdate)
// Pretty a lot of the same words, but I hope you got it :)
Little Example.. from Golang ...
type SomeOtherStruct struct {
gorm.Model
Id int
}
type SomeModel struct {
gorm.Model
someOtherStructId string
someField SomeOtherStruct `gorm:"foreignKey:SomeOtherStructId; OnDelete:Cascade,OnUpdate: SET NULL"` // basically foreign Key Relationship to model `SomeOtherStruct`
}
But I would like to prevent any Update/Deletion behavior, so Child Relation Models Objects won't get deleted after the Parent Model Object has been..
There is actually a concept from Django Framework (Python)
class SomeModel(models.Model):
some_field = models.ForeignKey(to=AnotherModel, verbose_name="SomeField", on_delete=models.PROTECT)
class AnotherModel(models.Model):
pass
As you can see, there is models.PROTECT constraint, that is basically what I'm looking for....
Is there any analogy for that in Golang GORM or some RAW SQL for that as well?
Thanks..
Unfortunately, you didn't mention which database you are using.
In Postgres (as an example) there are multiple options for ON DELETE:
NO ACTION
RESTRICT
CASCADE
SET NULL
SET DEFAULT
Only CASCADE will delete children if the parent is deleted. All other options (including the default NO ACTION) will make sure the children will "survive".
You can find more information in the postgres documentation: https://www.postgresql.org/docs/current/sql-createtable.html
Please feel free to update your question and/or comment with the database you are using.

schema design union vs flat properties

when I have a parent Object type that needs to point to a child Object type but that child Object's type can be of several types and only one can be chosen and populated. I see 2 options I can do with regard to graphql schema design.
option 1 - use union
type child1{......}
type child2{......}
union chooseOne = child1 | child2
type parent{
ref: chooseOne
}
option 2 use multiple props and have only one with data - the rest with nulls
type child1{......}
type child2{......}
type parent{
ref1: child1
ref2: child2
}
is there a 3rd option I am not thinking of? I am not that please with either. I feel like I am missing something... can anyone please comment? thanks! (edited)
am I missing a third possible option?
using an array
type Meeting{
.........(some properties)
recurrences : [Recurrence]
}
union Recurrence = Once | WeeklyRecurrence | MonthlyRecurrence | DailyRecurrence
Of course it looks like a relation ... and it is ... and gives you more possibilities.
all of them can have validFrom and validUntil times - you can filter out all historical entries automatically without manual disabling/removing
you can have AND combinations instead OR, for example 'every working day at 10.00, additionally at 15.00 on fridays'
you can process recurrence entries separately f.e. for notifications (having meeting id just fetch attendees from another relation)
But in fact maybe you don't need separate recurrence types at all, only one field/property (enumerated types) to know which fields are required for render/forms/resolver/mutations etc.
... all of them can use the same DB table, the same record structures in both cases (types mapped to enumed type field).
Update
I prefer 2nd option:
it's more readable/debuggable
it's easier to handle - if(ref1)...<Ref1Component data={ref1}/> ... passing union data object you don't have info about type!
unions sometimes leads to troubles like this

Specified cast is not valid.linq query c#

I have a table name LibraryInfo with these columns
[libraryId] [smallint] IDENTITY(1,1) NOT NULL,
[libraryName] [nvarchar](200) NOT NULL,
[mId] [smallint] NOT NULL,
[description] [nvarchar](300) NULL,
[updatedBy] [int] NOT NULL,
[updatedAt] [datetime] NOT NULL
I have designed a dbml file to access this table and create a method as follows:
public List<LibraryInfo> GetLibraryInfos()
{
var context = new BookDataClassesDataContext(){ ObjectTrackingEnabled = false };
return context.LibraryInfos.ToList();
}
when I call this method 'return context.LibraryInfos.ToList();' shows me 'specified cast is not valid'.
Is there anyone to help me.
You probably changed one of the column data types in your table or view after importing the table/view into your linq model.
Just re-import it so the data types of the auto generated model are the same as the db structure.
The problem seems to be related to the data type you are using. I recommend to use smallint rather than int. I had a similar some time ago, and later realized that querying tables with "int" data type causes the exact same problem. I changed int to Int16 and the problem was solved.
My former answer was obviously not correct. But:
You seem to have a mismatch of types here. ToList() on the context.LibraryInfos table would return a list of LibraryInfos objects (List<LibraryInfos>) instead of List<LibraryInfo>. So either your method needs to be declared as
public List<LibraryInfos> GetLibraryInfos()
or the code that returns the items needs to be changed to
return context.LibraryInfo.ToList();
This really depends on which one you want to return.
On your comment to your question:
context.LibraryInfo.ToList(); gives me error that dbml file does not contain a definition for LibraryInfo
Obviously you only have a LibraryInfos table in your data context. This means that you need to change your method return type to List<LibraryInfos>:
public List<LibraryInfos> GetLibraryInfos()
So the method now reads
public List<LibraryInfos> GetLibraryInfos()
{
var context = new BookDataClassesDataContext(){ ObjectTrackingEnabled = false };
return context.LibraryInfos.ToList();
}
Every item you get from the table has the type that matches the table name, as the LibraryInfos table is actually a collection of items of type LibraryItems.
You may have created a LibraryInfo class just because the compiler complained it didn't exist - you need to decide whether you can delete that from your project (look in solution explorer for LibraryInfo.cs file). But you can not cast between an item from the LibraryInfos table and that LibraryInfo class.

Coredata NSFetchRequest DictionaryResultType null properties Swift

Hello guys i am using this code to fetch the Result from Coredata
func getRequest(entiryDesc:NSEntityDescription) -> NSFetchRequest{
var request:NSFetchRequest = NSFetchRequest()
request.entity = entiryDesc
request.resultType = NSFetchRequestResultType.DictionaryResultType
return request
}
Now the problem is i need All the attributes which contains the Nil value too but the excutefetchrequest returns only those properties which have values , is there any work around for this to return Null attributes with String like "" every time i fetch ? Thanks Advanced
Of course, you can just dispense with the .DictionaryResultType and fetch normal managed objects. There are very few cases where the dictionary result type makes sense.
If you want to construct a dictionary with all attributes filled out (for whatever opaque reason), remember two things:
Make sure to insert the null values as objects NSNull()
You can use the NSEntityDescription API to generate all the attribute keys. Use entityDescription.propertiesByName.allKeys to generate a list of all attribute names of your entity.

LINQ to SQL -

I'm attempting to use LINQ to insert a record into a child table and I'm
receiving a "Specified cast is not valid" error that has something to do w/
the keys involved. The stack trace is:
Message: Specified cast is not valid.
Type: System.InvalidCastException
Source: System.Data.Linq TargetSite:
Boolean
TryCreateKeyFromValues(System.Object[],
V ByRef) HelpLink: null Stack: at
System.Data.Linq.IdentityManager.StandardIdentityManager.SingleKeyManager2.TryCreateKeyFromValues(Object[]
values, V& v) at
System.Data.Linq.IdentityManager.StandardIdentityManager.IdentityCache2.Find(Object[]
keyValues) at
System.Data.Linq.IdentityManager.StandardIdentityManager.Find(MetaType
type, Object[] keyValues) at
System.Data.Linq.CommonDataServices.GetCachedObject(MetaType
type, Object[] keyValues) at
System.Data.Linq.ChangeProcessor.GetOtherItem(MetaAssociation
assoc, Object instance) at
System.Data.Linq.ChangeProcessor.BuildEdgeMaps()
at
System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode
failureMode) at
System.Data.Linq.DataContext.SubmitChanges(ConflictMode
failureMode) at
System.Data.Linq.DataContext.SubmitChanges()
(.....)
This error is being thrown on the following code:
ResponseDataContext db = new ResponseDataContext(m_ConnectionString);
CodebookVersion codebookVersion = db.CodebookVersions.Single(cv => cv.VersionTag == m_CodebookVersionTag);
ResponseCode rc = new ResponseCode()
{
SurveyQuestionName = "Q11",
Code = 3,
Description = "Yet another code"
};
codebookVersion.ResponseCodes.Add(rc);
db.SubmitChanges(); //exception gets thrown here
The tables in question have a FK relationship between the two of them.
The parent table's column is called 'id', is the PK, and is of type: INT NOT NULL IDENTITY
The child table's column is called 'responseCodeTableId' and is of type: INT NOT NULL.
codebookVersion (parent class) maps to table tblResponseCodeTable
responseCode (childClass) maps to table tblResponseCode
If I execute SQL directly, it works. e.g.
INSERT INTO tblResponseCode
(responseCodeTableId, surveyQuestionName, code, description)
VALUES (13683, 'Q11', 3, 'Yet another code')
Updates to the same class work properly. e.g.
codebookVersion.ResponseCodes[0].Description = "BlahBlahBlah";
db.SubmitChanges(); //no exception - change is committed to db
I've examined the variable, rc, after the .Add() operation and it does, indeed, receive the proper responseCodeTableId, just as I would expect since I'm adding it to that collection.
tblResponseCodeTable's full definition:
COLUMN_NAME TYPE_NAME
id int identity
responseCodeTableId int
surveyQuestionName nvarchar
code smallint
description nvarchar
dtCreate smalldatetime
dtCreate has a default value of GetDate().
The only other bit of useful information that I can think of is that no SQL
is ever tried against the database, so LINQ is blowing up before it ever
tries (hence the error not being a SqlException). I've profiled and verified
that no attempt is made to execute any statements on the database.
I've read around and seen the problem when you have a relationship to a non PK field, but that doesn't fit my case.
Can anyone shed any light on this situation for me? What incredibly obvious thing am I missing here?
Many thanks.
Paul Prewett
Post up the schema of the parent table.
if you look here, some other people have had your problem.
http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3493504&SiteID=1
It appears that Linq2SQL has trouble mapping some foreign keys to some primary keys. One guy had a resolution, but I think you are already mapping to an IDENTITY column.
Since the database isn't being called I think you have to look at the mappings linq to sql is using. What does the Association look like? There should be an Association on both the parent and child classes.
Take a look at the linq to sql Association between the two classes. The Association should have a ThisKey property. The cast that is failing is trying to cast the value of the property that ThisKey points to, I think.
As far as I can tell there can be a problem when there is more than one key and the type of the first key does not match the type that ThisKey points too. I'm not sure how linq would determine what the first key is.
From the looks of it you only have one key and one foreign key so that shouldn't be the problem, but the designer, if you are using it, has been known to get creative.
I'm pretty much guessing, but this looks like something I've seen before.
Is this an example of this bug? If so, try running your code in .NET 4.0 now that the beta is out.
If, like me, you aren't ready to start using the beta, you may be able to work around the problem. The issue seems to be that LINQ does not properly support relationships defined on non-primary key fields. However, the term "primary key" does not refer to the primary key defined on the SQL table, but the primary key defined in the LINQ designer.
If you dragged your tables into the designer, then Visual Studio automatically inspects the primary key defined in the database and marks the corresponding class field(s) as "primary keys". However, these do not need to correspond to each other. You can remove the key Visual Studio chose for you, and pick another field (or group of fields). Of course, you need to make sure this is logical (you should have a unique constraint in the database on the field/fields you choose).
So I had 2 tables/classes related to eachother using an alternative key. The parent table had 2 keys: a surrogate primary key defined as an int, and an alternative natural key defined as a string. In the LINQ designer, I had defined the association using the alternative key, and I experienced the InvalidCastException whenever trying to update that association field on the child object.
To work around this, I went into the LINQ designer, selected the int, and then changed the Primary Key property from True to False. Then I chose the string, and set it's Primary Key property to True. Recompiled, retested, and the InvalidCastException is gone.
Looking at your screen shot it looks like you may be able to fix your issue by changing the LINQ primary key on ResponseCode from ResponseCode.ID to ResponseCode.ResponseCodeTableID
ResponseCode rc = new ResponseCode()
{
SurveyQuestionName = "Q11",
Code = 3,
Description = "Yet another code"
};
and:
INSERT INTO tblResponseCode
(responseCodeTableId, surveyQuestionName, code, description)
VALUES (13683, 'Q11', 3, 'Yet another code')
Are not the same, you are not passing in the foreign key reference. Now, I'm huge n00b at LINQ2SQL, but I'd wager that LINQ2SQL is not smart enough to do that for you, and it expects it as the first parameter of the anonymous dictionary, and is trying to cast a string to an integer.
Just some ideas.
This block:
codebookVersion.ResponseCodes.Add(rc);
db.SubmitChanges(); //exception gets thrown here
Can you try InsertOnSubmit instead of Add? i.e.
codebookVersion.ResponseCodes.InsertOnSubmit(rc);
I think Add is not meant to be used to insert records if my memory serves me right. InsertOnSubmit is the one to use.
To try and narrow down the culprit.
Have you tried replacing the anonymous dictionary with something like:
ResponseCode rc = new ResponseCode();
rc.SurveyQuestName = "Q11";
rc.Code = 3;
rc.Description = "Yet Another Code";
I've yet to really work with .NET 3.5 yet (day job is still all 2.0), so I'm wondering if there is an issue with passing the data using the anonymous dictionary (The cases don't match the SQL Columns for one).
Yea, I've read that and other posts, but it always seems to involve someone linking up to a field that simply has a unique contraint. Or in this guy's case (which does sound exactly like mine), he didn't get a solution.
Here's the parent table:
tblResponseTable definition (which maps to CodebookVersion)
COLUMN_NAME TYPE_NAME
id int identity
versionTag nvarchar
responseVersionTag nvarchar
versionTag does have a unique contraint on it, but that's not represented anywhere that I can see in the LINQ-to-SQL stuff - and since nothing ever goes to the database... still stuck.
Mike, I hear you. But no matter where I look, everything looks correct. I've checked and rechecked that the ResponseTableId is an int and that Id is an int. They're defined as such in the designer and when I go look at the generated code, everything again appears to be in order.
I've examined the associations. Here they are:
[Table(Name="dbo.tblResponseCode")]
public partial class ResponseCode : ...
...
[Association(Name="CodebookVersion_tblResponseCode", Storage="_CodebookVersion", ThisKey="ResponseCodeTableId", OtherKey="Id", IsForeignKey=true)]
public CodebookVersion CodebookVersion
{
...
}
[Table(Name="dbo.tblResponseCodeTable")]
public partial class CodebookVersion : ...
...
[Association(Name="CodebookVersion_tblResponseCode", Storage="_ResponseCodes", ThisKey="Id", OtherKey="ResponseCodeTableId")]
public EntitySet<ResponseCode> ResponseCodes
{
...
}
And a screenshot of the association in case that will help:
Any further thoughts?
ResponseCode rc = new ResponseCode()
{
CodebookVersion = codebookVersion,
SurveyQuestionName = "Q11",
Code = 3,
Description = "Yet another code"
};
db.ResponseCodes.InsertOnSubmit(rc);
db.SubmitChanges();
You may want to check to see that any fields in your database tables which are set by the db server when inserting a new record have that reflected in the Linq to SQL diagram. If you select a field on the Linq to SQL diagram and view its properties you will see a field called "Auto Generated Value" which if set to true will ensure all new records take on the default value specified in the database.
LINQ to SQL has been deprecated, FYI - http://blogs.msdn.com/adonet/archive/2008/10/29/update-on-linq-to-sql-and-linq-to-entities-roadmap.aspx.
I ran into a very similar problem. I'll link you over to my wordy post: http://forums.asp.net/p/1223080/2763049.aspx
And I'll also offer a solution, just a guess...
ResponseDataContext db = new ResponseDataContext(m_ConnectionString);
CodebookVersion codebookVersion = db.CodebookVersions.Single(cv => cv.VersionTag == m_CodebookVersionTag);
ResponseCode rc = new ResponseCode()
{
ResponseCodeTableId = codebookVersion.Id,
SurveyQuestionName = "Q11",
Code = 3,
Description = "Yet another code"
};
db.ResponseCodes.InsertOnSubmit(rc);
db.SubmitChanges();
Somewhere in your object graph there is a conversion error, the underlying data model (or the Linq To SQL model) has changed. This is typically something like NVARCHAR(1) -> CHAR when it should be STRING, or something similar.
This error is not fun to hunt down, hopefully your object model is small.
We had a similar problem, caused by using non-integer keys. Details and hotfix number are here: https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351358

Resources