ATG Repository - one to many mapping - atg

In our application, we have three tables dps_user, account, and profile for building user profile. The profile table has account_id as a foreign key. Based on this design, userprofile.xml is written. account_id is mapped as an item-type in xml which is working fine for one-to-one mapping. Every single account will have a separate profile.
Now we have a scenario one-to-many mapping (One profile associated to multiple accounts). We have a new table profile_account for this which has the mappings as below.
NEW_ID ACC_NO PROFILE_ID
====== ====== ==========
001 001 001
001 002 001
002 001 002
002 002 002
By default Account: 001 will be mapped to Profile: 001. Post-login we will get the new_id. With this value, we will fetch accounts and user will one of the accounts in the UI.
If user selects Account: 002 with new_id, then we have to update the profile with ACC_ID: 002. To achieve this, we retrieve the account item first and then update the corresponding profile item.
When doing this, we are getting below exception often and update is failing.
Error : java.sql.SQLException: java.sql.SQLSyntaxErrorException: ORA-02049: timeout: distributed transaction waiting for lock
Sometimes the update is successful in profile table but the old account is getting deleted from account table during this update. We have the cascade as insert,update,delete for account_id in profile table.
userProfile.xml:
<item-descriptor name="user" item-cache-size="3000" item-cache-timeout="900000" query-cache-size="1000" query-expire-timeout="900000">
<table name="PROFILE" type="auxiliary" id-column-name="user_id">
<property name="account" display-name="Account" column-name="ACCOUNT_ID" item-type="account" cascade="insert,update,delete" />
</table>
</item-descriptor>
<item-descriptor name="account">
<table name="ACCOUNT" type="primary" id-column-names="ID">
<property name="accountNo" data-type="string" column-name="ACC_NO" />
</table>
</item-descriptor>

Related

Facebook Marketing API - user_role

me/adaccounts?fields=user_role
What is the meaning of user_role? Is there a list of ID meanings?
https://developers.facebook.com/docs/marketing-api/aduser/v2.7#fields:
role
The role the user has on the account.
1001 = Administrator access
1002 = Advertiser (ad manager) access
1003 = Analyst access
1004 = Direct sales access (For a small number of directly managed accounts)
The user_role field is not a usable/useful field, I've filed to have it removed from the API.
More detail - as noted in other questions, the id returned does not conform to the role IDs (in the previous answer).
TL;DR - It's legacy code that will get removed.

What's the relationship between res.partner and res.user?

I am new to odoo v8 and i am not able to understand the relationship between res_partner and res_users tables and also with hr_employee table are they all related?
The relationship between res.partner and res.user is that res.user inherits from res.partner using an inheritance type called "Delegation Inheritance" (see documentation).
Because of "Delegation Inheritance" every res.user record has a mandatory internal connection to a corresponding res.partner record using a field partner_id. What is this connection all about is to directly use all the fields of res.partner to store data shared by res.user and res.partner (i.e. name, phone, etc... if for example you refer to phone property of a record of res.user you'll get the value stored in the corresponding res.partner record) so res.user has to define fewer number of fields on it's own, like password, login, etc..
Note also that because of this relation res.user can NOT exist in the system without corresponding res.partner, it's why every res.user has one, but nonetheless res.partner can exist without res.user.
hr.employee have m21 with res.users (user_id)
res.users have m21 with res.partner(partner_id)
Actually only res.users has a "real" relationship to res.partner, because with every user odoo will create a partner (per default no customer and no supplier). this partner will be used e.g. for emails and the followers system in odoo.
But you can have partners without users, too. That will be a normal partner, for defining customers and suppliers.
And finally there is the employee. You can set a user on it. If i recall right, the user will be used for attendances and timesheets.

Entity Framework - entity using a view giving duplicate data

I have the following view (SQL Server 2012 if it matters):
SELECT
EntityId
,EntityType
,StateId
FROM
SomeTable
INNER JOIN SomeOtherTable
When I generate an entity for this view (EF 6 - database first) it looks like this in the EDMX file:
<EntityType Name="VW_MyView">
<Key>
<PropertyRef Name="EntityId" />
<PropertyRef Name="EntityType" />
</Key>
<Property Name="EntityId" Type="Int32" Nullable="false" />
<Property Name="EntityType" Type="String" Nullable="false" MaxLength="2" FixedLength="false" Unicode="false" />
<Property Name="StateId" Type="Int32" />
</EntityType>
As you can see, the model generator created an entity key on the first two columns. The problem is, the first two columns do not guarantee uniqueness.
So for example I could have data like this in the view:
EntityId EntityType StateId
-------- ---------- -------
1234 CR 1
1234 CR 2
1234 CR 3
When I query the data using linq such as:
using (ContextA context = new ContextA())
{
var zList = context.VW_MyView.Where(f => f.EntityId == 1234
&& f.EntityType == "CR").ToList();
}
I get a list of three items, but like this (notice stateid duplicated):
EntityId EntityType StateId
-------- ---------- -------
1234 CR 1 <-- dupe
1234 CR 1 <-- dupe
1234 CR 1 <-- dupe
I migrated this exact same code from EF 4 (object context templates) to EF 6 (dbcontext templates), and before the migration it did not perform like this.
I know I can manually add an EntityKey to the StateId column, and it will work properly, but I have over 100 views in my model and I don't want to go through each one to check.
Why has this behavior changed, and is there a setting I can enable (globally) to correct this?
EDIT:
So based on the answers, I have been able to gather three ways to prevent this issue.
Add all primary key values from each consisting table into the view
Use nullif() tricks in the view to force columns to be non-nullable, and those be added by EF to the key
Manually add the Entity Key in the model myself
But this doesn't explain really why this happens, and how it could possibly be desired behavior? The EF linq query is simply returning entirely incorrect data, without any exceptions or warnings. I can't imagine this is correct.
I have the same "issue" in EF4 (with an .edmx file using the ObjectContext database-first approach) - not sure why it worked for you.
For Entity Framework, if it doesn't have a specified primary key (like on a table), it will fall back to using all non-nullable columns of that object (here: your view) as its compound PK.
These non-nullable columns are now the key for the table/view, and thus, only one value of that key can exist.
In order to resolve this, you need to either include more columns in your view to make the auto-detected key really unique (by including e.g. the primary key of all underlying base tables), or you need to manually set the key properly to something that works for you.
Another solution I found is by setting entity's MergeOption to NoTracking.
using (ContextA context = new ContextA())
{
context.VW_MyView.MergeOption = System.Data.Objects.MergeOption.NoTracking;
//Rest code goes here...
}
Solution found in this thread

Orm discriminator-column of the parent table must refer to a value which is of a different table

The question is quite confusing so I'll describe in detail as follows.
I have a domain object User (which has its respective User table in database). I have another domain Investor (which has its respective Investor table in database) that extends User. Now a User can be a Investor if User's userType='I'
<entity class="User" >
<table name="domain.Users" />
<discriminator-column name="user_type" discriminator-type="STRING"/>
</entity>
I need to map the user_type to its respective domain and tables.
<entity class="domain.Investor" >
<table name="domain.Users" />
<discriminator-value>I</discriminator-value>
</entity>
In the above code i cannot change the table name to the database's Investor table because the discriminator value is for User's table. I want the xml code where discriminator's column of Users table is I but it should have its own table Investor.
Investor should be able to use both the User and its own Investor table in a joined table inheritance structure if that is what you need. This will work out such that each row in User represents a User entity or User subclass, while each User that is really an Investor will also have a row in the Investor table. See http://wiki.eclipse.org/EclipseLink/Examples/JPA/Inheritance for a simple example of how to set up inheritance - you are missing the <inheritance strategy="JOINED"/> tag in User that specifies the JPA inheritance type to use.

Trying to control course content visibility to a moodle group

I am using moodle 2.2.4.
I have students in a course from district 1 and district 2. I have a request that the student in district 2 be assigned an advisor in the course. The advisor must only see the data of the student in district 2.
This is how I am trying to accommodate the request.
I created a new role called advisor based on the student role.
I created a new group in the course called group1.
I created a new account called group2_advisor
I enrolled group2_advisor in the role of advisor into group1 in the course.
I moved the student into group1.
When I log in group2_advisor, I can see just the district 1 student (which is great), BUT, I still see district 1 data when I click on the forum or quiz activities.
I initially based the advisor role on the non-editing teacher role, but that still showed both districts even after I had completed steps 1-4. When I based the advisor role on the student role I was only able to see the district 2 data (which is what i am after).
Any insights are very much appreciated.
Look at Moodle group default feature group content visibility.