training 6.6 data queries and widgets 2
Question

I am trying to add cast/crew to a movie but it is giving me this error. I walked all the steps i need to perform back but i don,t know why i cannot add cast/crew. Can somebody please help me. Thank you 

Solution

Basically, as per my understanding, You are trying to add the same person to the same movie with the same role. Only, in that case, you will get such an exception. 

For example:- If I have Along Came Polly Movie And Alan Rickman as Director, And if I try to do the same I'll get the exception. So That is what the requirement was Like the same person with the same role in the same movie should not get added. Also, You can customize this error feedback message. Look below i have done that


I will explain a bit actually in exceptional handling you are showing the exception that is getting raised.

But in the course, it is suggested to use such exceptional handling so that we can over hide the exception with a customized feedback message



As to why your UI is not showing the persons in a movie, that's down to a wrong filter in you aggregate

When you add multiple filters to an aggregate, all of them have to be true at the  same time.  (like an AND in SQL)

Do you aggregates will only return results if a person in a single personmovierole record is both director and producer, that's not possible.

So replace this

with this

and you will see your directors and producers.  

As far as I can tell, the SQL for the actors and crew is already correct, right ?

Dorine


Hi,


Can you share your data model with us? Your error is about an existing equal value already stored in the DB, and the index is set to unique (don't permit duplicates).


Thanks!


Best regards,

Ricardo M Pereira

Hi Ricardo,

thank you for the replay 

Hi,

Sorry, but we need to see your table in the DB, not the structure. The error that you have is about a submition to the database, so we need to understand if the problem is in your entity properties or in your code (that make possible the insertion for duplicates).

Can you share your OML with us? Maybe it's easier to check that.


Thanks!


Best regards,

Ricardo m Pereira

Hi Ricardo, 

I don,t know where i can find my OML, what does it stand for.

Kind regards,

Erdinc

Hi,

You can go to the service studio menu, Select Module/Export/Save. The file that you will save is the OML.


Hope this can help.


Best regards,

Ricardo M Pereira

Hi Ricardo,

Thank you for the explenation. In the annex you fill find the file. Thank you.

Kind regards,

Erdinc

OSMDb.oap

Hi,


I'm sorry, this file only have the core module, and, this module don't have any table (it's a base module):


Best regards,

Ricardo M Pereira

mvp_badge
MVP

Hello Erdinc,

Hope you're doing well.

You're exporting an OAP file named OSMDb.oap which corresponds to an application.

Inside of it, there is only one module OSMDb_core, but you don't have any tables inside of it:

So I guess this is not the module where you have your data model and entities defined :)

Also, if you want to export only a module (instead of an application), which corresponds to an OML file, you should go to Module -> Export -> Save / Save As (like mentioned by Ricardo):


This will allow you to export only that specific module (OML file).


Kind regards,

Rui Barradas

Hi, 

Sorry i send the wrong file. Thank you for the explanation Rui.

In the annex you will find my correct file.

Kind regards,

Erdinc 

OSMDB.oml

mvp_badge
MVP

Hello again Erdinc,

Thank you for sharing your OML file.

As I can see, your entities are stored in ToDo_Core__yourinitials_ module:

Can you please share your OML file for this module?

Also, I'd suggest that you change the name of this module, since it is not a friendly / conventional name for a module :)


Kind regards,

Rui Barradas

Hello Rui,

In the annex you will find the requested OML files. I also changed the name but it will not change at OSMDB data.

Kind regards,

Erdinc

OSMDBEB.oml

This is the other file

OSMDbCore.oml

This is the right file, but the file is on a different map and it will not allow me to place it under the map that i am using as my main

CoreOSMDBv4.oml

Hey Erdinc Burnik

As I can see in the exception you have attached, It says that the combination of movieId, PersonId, and PersonRoleId Should be unique every time.

Solution

1 If you want to keep the data unique, then Change the "CreatePersonMovieRole" Action with "CreateOrUpdatePersonMovieRole". 

2 If you want duplicate records of such combination then refer to the highlighted field marked as 2. And Change the value of Unique to No. 

  To open this Detailed popup. Double click on the MORE option available in the entity detail. which is highlighted as 3

After that change the value. Publish your code. and retry the action.


 Erdinc Burnik Kindly mark it as a solution if my suggestions are helpful.


Thanks & regards

Divya Nayak


Hi Divya,

Thank you for your answer. I tried both but it did not work. By the second i cannot change it from yes to no.

Kind regards,

Erdinc

Solution

Basically, as per my understanding, You are trying to add the same person to the same movie with the same role. Only, in that case, you will get such an exception. 

For example:- If I have Along Came Polly Movie And Alan Rickman as Director, And if I try to do the same I'll get the exception. So That is what the requirement was Like the same person with the same role in the same movie should not get added. Also, You can customize this error feedback message. Look below i have done that


I will explain a bit actually in exceptional handling you are showing the exception that is getting raised.

But in the course, it is suggested to use such exceptional handling so that we can over hide the exception with a customized feedback message



Hi Erdinc,

As far as I can tell, you executed the exercise as described.  

1° the index on movie + person + role is unique on purpose, to prevent duplicate information to be added to the database, so that's fine.

2° in the 6.6 exercise, they just propose you have a screen on which you select a person and a role for a given movie, and execute the Create on PersonMovieRole.

So I think the error message you are getting is completely to be expected if you try to add the same person with the same role to the same movie.  That's just the unique index kicking in to prevent duplicates.  So can you maybe confirm this to us : the person and role you are trying to add to the movie, is already present in the database ?

I had a quick look further down the line in the next exercises, about validation, but didn't see anything they do in the exercises to amend this.  

So I'll just give you the short here :

you'll learn about validations soon, and typically when there are constraints on the data (such as this unique index), there's a number of approaches :

1° prevent bad combinations to be selected (which would be a bit harder in this specific example)

2° perform validations to verify if it's not a bad combination before attempting the create

3° trying the create and in case of an exception trying to give a meaningfull message to the user

In my opinion, if at all possible options 1 and 2 should be used, 3 is a weak solution

So, in your particular example, in the Save action, you could execute an aggregate reading into the database with filter on movie + person + role, if found, then give user feedback that this has already been added, if not found, execute the create.


Hope this clarifies a bit, if not, more will become clear when you get to the tutorials on validations, but as far as I can see, you are not doing anything wrong so far.

Happy Coding,

Dorine



Hi Divya,

I have implemented what you explained me but i cannot see the directors and producers that i added in the UI. Do you know how i can fix that.

Kind regards,

Erdinc

Hi Dorine,

Yes the person that i am trying to place in the database are the same, but i am not seeing them in the UI

Kind regards,

Erdinc


As to why your UI is not showing the persons in a movie, that's down to a wrong filter in you aggregate

When you add multiple filters to an aggregate, all of them have to be true at the  same time.  (like an AND in SQL)

Do you aggregates will only return results if a person in a single personmovierole record is both director and producer, that's not possible.

So replace this

with this

and you will see your directors and producers.  

As far as I can tell, the SQL for the actors and crew is already correct, right ?

Dorine


Hi Dorine,

Yes, i was trying to get the director and producer to display but i could not figure out what was wrong. Thank you. Yes the SQL was correct.

Kind regards,

Erdinc

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.