Questions tagged [joined-subclass]

Joined-subclass is a mapping strategy in Hibernate and NHibernate that is also known as "Table per subclass".

Joined-subclass mapping is a mapping strategy in Hibernate and NHibernate where a superclass A is mapped to its own table and all subclasses that extend A is mapped to their own table, but with a join to A's table. Only the properties defined at each level in the inheritance hierarchy will be stored in corresponding columns in each class' database table.

When selecting a derived class B from the database, Hibernate does a select on A with a left outer join on B as well as all other classes extending from A. Depending on which left outer join returns any data, Hibernate constructs a new instance of the correct class (in this case, B) and fills it with data from table A and B.

70 questions
2
votes
0 answers

NHibernate multiple joined subclasses and duplicate column names using criteria

Assume we have this entity structure: Document - DocumentA - DocumentB In base class Document we have fields Id, Name, CreateDate. In joined subclass DocumentA we have fields Book, Pages. And in DocumentB we have Magazine, Pages. So the problem is…
2
votes
0 answers

Mapped subclass is retrieved as superclass by Hibernate

I have a class Project, a superclass Resource with two subclasses StorageResource and ComputeResource. I have defined a Hibernate mapping (I am using Hibernate version 5.3.7.Final) as follows: @Entity @Table(name = "PROJECTS", ...}) …
Giorgio
  • 5,023
  • 6
  • 41
  • 71
2
votes
1 answer

With Hibernate joined-subclasses, is it possible to duplicate columns in super and sub-tables *and* keep them in sync?

So I have an interesting situation. I've inherited a big mess of code where the original developer decided to forego using inheritance in favor of enums and switch statements...it's a perfect example of this anti-pattern Now it's time to refactor,…
stevevls
  • 10,675
  • 1
  • 45
  • 50
2
votes
1 answer

NHibernate (3.1) subquery on subclass not joining base class table

The following is an abstraction of an actual problem I'm having. public class Base { public virtual string Id { get; set; } public virtual string Foo { get; set; } } public class Sub : Base { public virtual string Bar { get; set; } …
Travis Heseman
  • 11,359
  • 8
  • 37
  • 46
2
votes
0 answers

Hibernate filter in subclass

I have super model Animal that have sub classes like Cat and Dog. I define Cat and Dog subclass with discriminator in hbm file. Now i wanna load all Animal and enable hibernate filter via dao but each sub classes have different filter…
Javad Kargar
  • 1,275
  • 1
  • 12
  • 27
2
votes
2 answers

How can I model this object hierarchy in Fluent NHibernate without violating DDD principles?

I am trying to build a domain model that will allow me to manage Contracts. The Contract class is my aggregate root, and it has a single property right now, which is Reviewers. Reviewers, in the context of the Contract, each have a property to it's…
Joseph
  • 25,330
  • 8
  • 76
  • 125
2
votes
2 answers

Hibernate subclass with foreign key relationships

I need some help defining the following object hierarchy/ database relationship in Hibernate From the object sense – Agent is inherited from Person and Agency is inherited from Organization. they are inherited from Party which can have multiple…
shikarishambu
  • 2,219
  • 6
  • 35
  • 57
2
votes
1 answer

How to avoid unnecessary inner join on a simple query on entity inheritance mapped with JOINED strategy?

I'm using JPA 2 with Hibernate 4.2.0-Final as provider and I have the following entities: @Entity @Inheritance(strategy=InheritanceType.JOINED) public class Person { @Id private String id; .. Person attributes .. .. Getters/Setters…
Rafael Vanderlei
  • 351
  • 2
  • 10
2
votes
1 answer

how to map a one-to-many collection to a joined subclass when key is in the parent class

I'd like to map a one to many collection to a subclass but the key of the collection is an attribute of the parent class. Currently i'm mapping AbstractFoo Foo and Bar class like this :
needle
  • 145
  • 5
2
votes
1 answer

NHibernate search specific subclass

Is it possible to filter on a particular joined-subclass in NHibernate? For example, I have the following classes: Pet { Name } Cat: Pet { Paws } Budgie: Pet { Wings } Person { Pets } I want to create an NHibernate search to give me Persons with…
Kram
  • 4,099
  • 4
  • 39
  • 60
2
votes
1 answer

jpa how to create new entity with same id as parent entity (JOINED Inheritance)

my question is very similar to Changing the type of an entity preserving its ID, but instead i´m using InheritanceType.JOINED instead of Table_per_class. This means i don´t to change any table, just to create a new subclass, with the same id as the…
Luiz Henrique Martins Lins Rol
1
vote
1 answer

Loading collection in base class from joined-subclass with NHibernate

I have a class with some properties and a collection of names like so: public class A : BaseObject { private Int32 zindex; private Int32 atNmNr; private IList names = new List(); } Then I have a class B that…
1
vote
0 answers

Can I search subclasses by type without joining every subclass table using Hibernate?

I am using spring data jpa. I am using InheritanceType.JOINED for my inheritance strategy. Say I have the following entity relationships: Animal (abstract class) Cow extends Animal Pig extends Animal Cat extends Animal etc.. Each animal has a…
1
vote
1 answer

Unknown entity issue for joined subclass when using annotation

I met exception when using annotated joined subclass, i don't know how to correct it, please help. Exception is: org.hibernate.MappingException: Unknown entity: B Code: Class…
liuhebing
  • 13
  • 1
  • 3
1
vote
1 answer

Hibernate cannot create joined sub-class table while using annotation

I am new to Hibernate and I cannot create joined sub-class table while using Hibernate annotation. Here is my code. This is the main class. @Entity @Table(name="CRM_User") @Inheritance(strategy=InheritanceType.JOINED) public class UserImp extends…
Charles
  • 675
  • 3
  • 12
  • 21