In which case do you use the JPA @JoinTable annotation?

EDIT 2017-04-29: As pointed to by some of the commenters, the JoinTable example does not need the mappedBy annotation attribute. In fact, recent versions of Hibernate refuse to start up by printing the following error: org.hibernate.AnnotationException: Associations marked as mappedBy must not define database mappings like @JoinTable or @JoinColumn Let’s pretend that you have an … Read more

How do I access the child classes of an object in django without knowing the name of the child class?

(Update: For Django 1.2 and newer, which can follow select_related queries across reverse OneToOneField relations (and thus down inheritance hierarchies), there’s a better technique available which doesn’t require the added real_type field on the parent model. It’s available as InheritanceManager in the django-model-utils project.) The usual way to do this is to add a ForeignKey … Read more

What is related_name used for?

The related_name attribute specifies the name of the reverse relation from the User model back to your model. If you don’t specify a related_name, Django automatically creates one using the name of your model with the suffix _set, for instance User.map_set.all(). If you do specify, e.g. related_name=maps on the User model, User.map_set will still work, … Read more

Create code first, many to many, with additional fields in association table

It’s not possible to create a many-to-many relationship with a customized join table. In a many-to-many relationship EF manages the join table internally and hidden. It’s a table without an Entity class in your model. To work with such a join table with additional properties you will have to create actually two one-to-many relationships. It … Read more