ER Diagram Entity without attribute - sql

I have designed an er-diagram and have an entity without any attributes. I need this entity (Item) to create a many-to-many relationshop but I guess there is a way to make this more efficient and getting rid of the entity without attributes.
ER DIAGRAM:
Thanks

As I can see from your diagram your Item isn't just entity without attributes. It's a base type for your BAGEL and DRINK (you can think of this relationship as inheritance in OOP languages).
There are some techniques to work with inheritance in database world. So this Item is not a problem for ER-diagram.

ITEM should have at least one attribute - an identifier. A supertype's primary key can be reused as a foreign primary key in its subtypes.

Related

An entity relationship diagram shows the relationship between entities, but how do you show the relationship between attributes?

Say I had three types of vehicle, which are all related by some similar attributes.
What is the best way to show these relationships?
In traditional entity-relationship diagrams such a relation between attributes is not shown. This notation is exclusively reserved for foreign keys to primary keys relationships. For example if you would have a Manufacturer entity with a (unique) Id attribute, you could then relate a new attribute Car manufacturer id to it to show to what entity it refers.
In an enhanced ERD, you could use the IsA relationship and move the common attributes to a separate entity called Vehicle. The IsA relationship would then mean that the same attributes are inherited by the inheriting entities. But your example is not straight forward, since a Boat has no Number of wheels. So you'd need to further add a Rolling vehicle entity, making the diagram very complex.
Very pragmatically, you could:
Use the same attribute name for the same kind of information.
Use a data dictionary describing each unique attribute in a generic way applicable to all teh entities that use it.
Or graphically use some dotted connector between common attributes (instead of the plain lines which are confusing)
Or, if the similar entities are close on the diagram, draw colored horizontal boxes surrounding groups of identical attributes.

Doctrine 2 : Best way to manage many-to-many associations

Doctrine2 ORM have 2 technical ways to handle many-to-many associations :
1/ For a "simple" relation between 2 entities, and without additionnal attribute :
Use #ManyToMany associations between entities
In this case, the link table is used directly, without an association entity
2/ When link table introduces extra fields or more than 2 entities :
Use an association class, ie an "real" entity to map the link table
In this case, the direct ManyToMany association is replaced by OneToMany/ManyToOne associations between the participating entities
These 2 implementations are quite different.
But, in some cases, future business requirements can quickly need to change simple associations, by adding extra fields for example.
In this case, we must replace direct ManyToMany associations in existing entities by the second implementation and refactor affected code.
So, is it a good way to always use association entities to handle all
ManyToMany associations ?
Otherwise, what are the best practices for
choosing the good implementation and handle these kind of domain
model evolutions ?
If you have a good reason to belief that in the near future you will have extra properties on your ManyToMany join table then it's a good idea to make an entity out of precaution. If not then it's better to use the normal ManyToMany relationship. Then when a change is needed you can update your schema along with your code. If you try to follow the Single responsibility principle then you can avoid refactoring large amounts of code.

Fluent NHibernate auto mapping - how to create a many-to-many relationship table?

just wondered if anyone know if there is a way to crate a Many-to-Many relationship table automatically using some attribute? without creating the table, or mapping a class to become that relation table.
If i add the attribute [ManyToMany(3,Class="DeploymentListUsers")] i get an error that this class isn't mapped to the DB.
NHibernate.MappingException: An
association from the table Users
refers to an unmapped class:
I don't want to define the class myself, nor creating the table in the DB before hand.
it's seems possible in JAVA, does fluent NHibernate is a fully implemented version of hibernate and JPA annotations?
http://www.hiberbook.com/HiberBookWeb/learn.jsp?tutorial=19mappingmanytomanyrelationships
Thanks,
Itay
If you specify a class, you must make sure it exists too. NHibernate will not create a class for you. If however, your many-to-many table only contains a foreign key to your deployments table and a foreign key to your users table, you won't need such a class. You will only need a separate many-to-many mapping class if you want to store additional facts about the relation.
As far as I can tell, in your situation you just need to create the many-to-many table (you could use NHibernate's SchemaExport() to generate the CREATE TABLE statement so there's some automation there) and tell NHibernate how to map to it. Unlike you, I don't use mapping attributes so I don't know how to do map using them but it is probably very simple.
NHibernate now supports JPA (called NPersistence or NPA for the .NET platform) including JPA annotations.
It is the best way to specify relations and have your code portable for other vendors as well.
check it out:
www.npersistence.com
My answer to a similar question might help you out: https://stackoverflow.com/a/12198533/185200
I ended up extending the many-to-many automapping step to support properties decorated with a custom attribute.

Does NHibernate support mapping an abstract class to disparate tables using composite ids?

I have a complex, 3NF database being provided to me for a particular project. I would like to avoid using a class-per-table domain design. Rather, I would like to model my domain objects after how they are used from a conceptual business perspective.
The rub is how to properly persist this information. I know I can go the ADO route, but I'd like to take a stab at using NHibernate, having used it successfully on other projects with more flexible data stores.
So, I need to know if NHibernate will support the following scenario:
I have a conceptual object known as a ProjectStatus, which is comprised of a handful of date stamps for various activities along with some notes about the status. All of the data that comprises the ProjectStatus comes from 2 or more tables. There is no ProjectStatus table.
I know I can do a union-subclass in my NH mapping to get this to work, but...
One of the tables that holds the bulk of the information I need has a composite id (two PK fields that together make up the identity signature). I know NH supports composite ids as well, but how would I go about mapping my the union on the composite key? Do I need to specify a composite key underneath the union-subclass section?
The dba has refused to budge on her near-neurotic 3NF data model, so I'm stuck on that front. If I have to drop to ADO for ease/speed of development, so be it, but I'm hoping NH will rise above...
I gather that you have a base-class and two sub-classes that you want to map to two sub-class tables using the table-per-concrete-class mapping strategy. The two sub-class tables need to declare the same primary keys, and the primary keys need to be mapped in the base-class mapping. You have to declare the id or composite-id in the base-class mapping, so that you can ask NHibernate for an object of the base-class type with the given ID or composite ID. You can't declare them in the subclass-mapping, and you certainly can't declare them to be different for each subclass type (that's what declaring them in the subclass mapping would permit you to do), because from a strongly*-typed object-oriented perspective, that would be leaving the realm of sanity.
*Strong typing, to me, means that variables are statically typed (the type of each variable is known to and enforced by the compiler) and objects are strictly typed (the type of each object is known to and enforced by the runtime).

Nhibernate: Make Many-To-Many Relationship to Map as One-To-One

I have two items A and B, which have a uni directional one-to-one relationship. (A has one B)
In the database these are represented by ATable and BTable, and they are linked together by ABTable. (From the database setup it appears there is a many-to-many relationship but there is not, it was done this way for normalization reasons).
The problem is due to this setup, I have only been able to get NHibernate to map this as a many-to-many relationship between the entities. Is there anyway of making the entities have a one-to-one relationship?
The best I could think of is to leave its has a many to many relationship, and then have two properties on the A entity one that returns a List of B, which would satisfy the mapping and a second non-mapped property that would get the first B from the list, to satisfy my application. - but this seems un-eligant.
Are you sure you mean a one-to-one? I've had so many people ask for one-to-one's when they really mean many-to-one's.
Anyway, short of changing your schema, the easiest thing is what you suggested; however, to make it a little cleaner, you can make the collections private so you're only exposing the two properties that fetch the first item. You can see the various methods in Fluent NHibernate for mapping private properties on the wiki.
You might try combining the join-table with one-to-one mappings in various ways. A join-table mapping permits a single class to be persisted across more than one table which have a one-to-one relationship.