Why EclipseLink is adding discriminator column for joined inheritance strategy? - jpa

I am using JOINED inheritance strategy with EclipseLink JPA implementation. I have noticed that EclipseLink is adding discriminator column, named by default DTYPE, to the database schema. I understand, that discriminator is needed for one table inheritance strategy, but why for JOINED strategy?
EclipseLink needs this column because I've got errors after removing it. Is this column added for performance reasons, etc? I am not particularly happy about that since from the point of view of database schema this column is just unnecessary clutter.
Hibernate based JPA does not do anything similar.

From Joined Table Inheritance:
In the joined table inheritance, each
class shares data from the root table.
In addition, each subclass defines its
own table that adds its extended
state. The following example shows two
tables, PROJECT and L_PROJECT, as well
as two classes, Project and
LargeProject:
...
The discriminator column is what determines the type and thus what joined table to use so you need a discriminator column in the parent table.

Related

Is it possible to use DBIx::Class on a database without relationships?

I'm new to DBIC. I've imported data into a database. It's not possible to create relationships between the tables because, apparently, not all the values in the child table's foreign key column have a corresponding value in the parent table.
So is it possible to still do joins between the tables? I've skimmed through the tutorial and documentation but found nothing that addresses this problem.
You can of course define relationships in your DBIC schema that don't have a matching constraint in the database.
If you use $schema->deploy it will automatically generate constraints for all foreign key columns.

JPQL Foreign Key as condition in NamedQuery()?

I want to realize two tables, table one has OnToMany and Table two is ManyToOne (so we have a 1 : N relation). Solution: Avoid reserved words.
Looks like your JPA provider does not automatically quote SQL reserved words for you (ORDER) and so the RDBMS is objecting to the SQL thrown at it.
If that is the case (easily checked, can you do a simple query with no WHERE clause?) then you'll have to set the table name as 'ORDER', or change its name to a non-keyword, or use a JPA provider that does auto-quote such things for you (e.g DataNucleus JPA).

EF many to many with junction entity database first

I have a junction table with and idenity primary key columns to realize a many to many relationship. Visual Studio automatically detects it as a many to many relationship and the junction table is not an entity.
How can i realize it that also this table is generated as an entity? I need this for breeze.js .
You just need to add additional columns (or properties) to that table (or model).
You said that your table has acolumn named ID and it's the primary key withe IsIdentity set to true. It must works, I'm using this approach...
There must be a problem or missing with your table definition. However, if all are OK, just add a nullable column in your table and update your model from database. The problem will go away.

Entity Framework 4 - Use a single mapping table for all many-to-many relations

I would like to map all many-to-may relations through a single table in my database.
Meaning that I have numerous tables (entities) that have various many-to-many relations. Instead of having a separate mapping table for every relation I would like to use one "master mapping" table having to columns: End1Id & End2Id.
Don't ask why ;) It's required by my customer...
How would I set this up in the model designer, or do I have to edit the edmx xml directly....or is it just not possible?
Thanx for your help!
In such a scenario you can't have explicit foreign keys, because a table like this normally has at least three rows:
PK of table 1
PK of table 2
Type of mapping, which specifies the exact tables to use.
Because of that, you can just create a table in EF, but it will also have no connections to other tables and you will have to do the joins manually.
You would need to set this Master Mappings table manually. The designer doesn't do it for you automatically.
However - if denormalized entities are what you are looking for, better have those denormalized in DB level rather than in EF/code level.

How to handle "secondary" keys in Entity Framework

I'm evaluating using EF against an existing schema - the problem is that I can't work out how to set up associations between tables where the foreign key is NOT the primary key of the master table.
As an example, a foo may have many bars as defined like this (forgive the pseudocode):
table foo {
int foo\_id pk,
char(10) foo\_code,
...
}
table foobar {
int bar\_id pk,
char(10) bar\_foo\_code fk(foo.foo\_code),
...
}
What am I missing to be able to create the foo_foobar association, and hence a Bars navigation property on the Foo entity?
Linq to entities doesn't support Foreign Keys which don't point to the primary key of a table (see log message 3). Linq to entities will treat it as a normal field on a table. You won't be able to navigate to the entity it's linked to.
If you have an existing schema i'd recommend using the edm generator as this will create the EMDX file, code behind and even the view code (which can be very large). If your existing scheme is quite large Check out this post, which explains how to deal with large schemas.
When you run the EDM Generator you'll find out all the things that are not supported.
Looking at a previous EDMGen2.exe log we got the following types of messages back:
The data type 'sql_variant' is not
supported, the column 'ColumnName'
in table 'TableName' was
excluded.
The table/view 'tableName' does not
have a primary key defined. The key
has been inferred and the definition
was created as a read-only table/view
The relationship 'RelationshipName'
has columns that are not part of
the key of the table on the
primary side of the relationship
which is not supported, the
relationship was excluded.
We've also found that the Linq project actually crashed Visual Studio quite alot as the code file produced by EDM was well over 80 mb.