eclipselink jpa joined table inheritance with mappedsuperclass - jpa

I have 2 tables. Employee and EmployeeDetails. Employee table has the basic details like Employee Id, Department and some audit fields like Created By, Created Timestamp. EmployeeDetails table has all the personal details about the employee and same audit fields (Created By, Created Timestamp) like Employee table. Now the audit fields and Version column are part of a MappedSuperclass ModelBaseFields.
I am using JOINED Inheritance in Employee which is my base class. It extends ModelBaseFields which is a MappedSuperclass. EmployeeDetails extends Employee.
Now the problem is, whenever I try to persist the data, Employee table INSERT query is formed properly however, EmployeeDetails INSERT query is missing audit fields (Created By, Created Timestamp) and version column.
I have tried using SINGLE TABLE inheritance with Secondary table. I am getting same issue in that scenario as well.
How do I add common columns in child table?

Related

Master-detail custom database update sequence using entity framework

I have 3 tables with the relationship as: CompanyStatus and Employee is the child table of Company, CompanyStatus and Employee is not link to each other.
When perform insert data using entity framework, by looking at the profiler, i notice that the update sequence of entity framework as below
1. Company
2. Employee
3. CompanyStatus
The problem is: i have an insert trigger in Employee table which check the CompanyStatus of the related Company and base on that perform some database update action. So when the new row has been inserted into Employee table, the CompanyStatus is not exists yet. How can i change the update data sequence of entity framework and make it insert data with the custom sequence like:
1. Company
2. CompanyStatus
3. Employee.
Thanks in advance

Spark Scala Dataframe join and modification

I have a table which has employee details and another table project which has the project details and employee id assigned.
Employee
EmployeeName|Id|Address|Assigned
Joan|101|xxxx|y
Project
ProjectCode|Number of days|Employee
XX1223|24|101
I have a csv file which will load the employee details in the employee table. While loading the employee details,
I need to identify if his employee id is assigned to the project table:
if the employee id is available in the project table, insert y to Assigned in the Employee table.
if not, insert n to Assigned in the Employee table.
I have a dataframe for Employee as,
var employeeDF = Employee_TABLE
And,
var employeeAssignedDF = Employee_Join_Project
At the moment, I insert to Employee first then do the join and then update Employee again. But I can do the
employeeDF.except(employeeAssignedDF)
which will have a minimum number of rows.
Is it possible to change few of the data frame column alone?
I want to insert to the table only once, so when I join and do the except I should have all the records which can be inserted to DB. Is that feasible?
Thanks
You could try this, But not sure whether this could solve your problem or not -
val newDf = df.withColumn("Column", when(CONDITION, 'Y').otherwise('N'))
You could also use any method at the place of "when(CONDITION, 'Y')"

Entity Framework - How to Insert to table with foreign keys without retrieving foreign table rows first

I'm having a hard time finding the exact answer to this question, so my apologies if this is redundant.
So I have 3 tables defined such that:
Person :PersonId, FirstName, LastName
Company: CompanyId, CompanyName
Order: OrderId, PersonId, CompanyId
On the Order table, there is a foreign key defined on the PersonId and CompanyId columns, thus, my Order entity class generated by EF has a navigation properties of type Person (not PersonId) and Company.
So, to insert into the Order table, I first need to query the person and company tables to get the person and company entities. Then I can construct the Order object using the Person and Company entities and save it to the db.
In my scenario, I am being passed a PersonId and CompanyId.
In classic SQL I would just do INSERT INTO Order Set (CompanyId, PersonId) - 1 database call. But with EF, I have to do 3 db calls. This seems like overkill.
Is there any way around this?
PS - I'm using EF 6. I know I could generate an expression and make it single call..but that would still yield two subselects.
You can just include foreign key properties in addition to the navigation properties and then set them using the ids you have. If you do this will not have to go to the database to get related entities for just a sake of setting the relationship.

Can I reference an existing row in base table from inherited one?(postgres)

I'm trying postgres, version 9.2
Can I reference an existing row in base table from inherited one?
Example:
i have a "person" table and a "student" table which inherits from person.
As i understand, if i insert new student, automatically new person is added.
But i need to insert first the person data, and then insert a reference to it and student related data.
As i understand, if i insert new student, automatically new person is added
No. Although you can select students by querying the person table, only the student table will be populated after an insert to the student table.
The relationship you want is foreign key not inheritance. Create the person id column in the student table and make it dependent on the person id on the person table.

Need help with Entity Framework Relationshipships

I'm new to Entity Framework and just experimenting...
Consider 3 db tables where Person is a base table. I want the Employe table to enherit from Person, storing employee specific info. It seems that EF requires that PersonId also be the PK of the Employee table, so I made EmployeeID a unique index.
Next I added a table, Application, which stores one record for every software application that the Employee supports, creating a foreign key from Application.EmployeeId to Employee.EmployeeId.
However, EF doesn't seem to recognize relationships that involve unique indexes, but only Primary Keys.
What I can do is create a relationship from Application.PersonId to Person.PersonId, however, only Employees can be responsible for an Application, so it seems more natural to me to have Application as a "child" of the Employee table rather than the Person table.
Is this possible in EF?
You can build your relation between Employee (PersonId) and Application (EmployeeId). In such case the integrity should work as you expect because only PersonIds in Employee table will be only for existing employees. EF has currently no support for unique keys.