single-table-inheritance

Hibernate: Parent/Child relationship in a single-table

孤街醉人 提交于 2019-12-03 13:06:17
I hardly see any pointer on the following problem related to Hibernate. This pertains to implementing inheritance using a single database table with a parent-child relationship to itself. For example: CREATE TABLE Employee ( empId BIGINT NOT NULL AUTO_INCREMENT, empName VARCHAR(100) NOT NULL, managerId BIGINT, CONSTRAINT pk_employee PRIMARY KEY (empId) ) Here, the managerId column may be null, or may point to another row of the Employee table. Business rule requires the Employee to know about all his reportees and for him to know about his/her manager. The business rules also allow rows to

Changing type of ActiveRecord Class in Rails with Single Table Inheritance

心已入冬 提交于 2019-12-03 09:34:40
I have two types of classes: BaseUser < ActiveRecord::Base and User < BaseUser which acts_as_authentic using Authlogic's authentication system. This inheritance is implemented using Single Table Inheritance If a new user registers, I register him as a User. However, if I already have a BaseUser with the same email, I'd like to change that BaseUser to a User in the database without simply copying all the data over to the User from the BaseUser and creating a new User (i.e. with a new id). Is this possible? Thanks. You can just set the type field to 'User' and save the record. The in-memory

Hibernate HT_ Temporary Tables ON JOINED inheritance, Migration from Hibernate 3.4.0.GA To 5.1

这一生的挚爱 提交于 2019-12-03 05:28:37
I'm trying to migrate an application from Hibernate 3.4.0.GA to Hibernate 5.1, and after complete the required changes on java code, when I deploy the application I'm watching how Hibernate is trying to create HT_ tables (global temporary), one for each @Inheritance annotated entity. Searching on Google I've found why the tables are being created. But in my case we are not allow to change de database to add new tables. My Inheritance model only has one level of Inheritance and its simple, example Does anyone knows any alternative representation for a hierarchical table structure that I can use

Need classic mapper example for SqlAlchemy single table inheritance

主宰稳场 提交于 2019-12-02 05:26:20
I found an example of how to do single table inheritance using Class mappings. http://docs.sqlalchemy.org/en/latest/orm/inheritance.html#single-table-inheritance But for the life of me, I cannot find an example of how to do this with classic mapper so that I can keep my classes and persistent mappings separate. How do I convert this example into classic mapping? I am clear on creating the tables, just not sure how to actually structure the mapper. In the example, there are the following types defined: class Employee(Base): class Manager(Employee): class Engineer(Employee): Assuming I have

How to use @UniqueConstraint with single table inheritance (JPA)?

瘦欲@ 提交于 2019-12-02 05:17:09
问题 I have a class extending an existing entity with single table strategy (which I can't change). I want to use UniqueConstraint for that entity so I tried: @Entity @Table(name = "t_document") public class Document implements Serializable { ... } and @Entity @Table(uniqueConstraints = { @UniqueConstraint(name = "Test", columnNames = { ... }) }) public class MyDocument extends Document { ... } The unique constraint is not used at all, nothing in log file. Is this the correct way to use

How to use @UniqueConstraint with single table inheritance (JPA)?

♀尐吖头ヾ 提交于 2019-12-02 00:26:41
I have a class extending an existing entity with single table strategy (which I can't change). I want to use UniqueConstraint for that entity so I tried: @Entity @Table(name = "t_document") public class Document implements Serializable { ... } and @Entity @Table(uniqueConstraints = { @UniqueConstraint(name = "Test", columnNames = { ... }) }) public class MyDocument extends Document { ... } The unique constraint is not used at all, nothing in log file. Is this the correct way to use UniqueConstraints in this situation? (We use JPA2, JBoss 7.1) You cannot override the base class @Table

Single Table Inheritance to refer to a child class with its own fields

爷,独闯天下 提交于 2019-12-01 00:46:32
I am using Ruby on Rails 3 and I implemented a working Single Table Inheritance like the following: class User < ActiveRecord::Base # Schema Information # # Table name: User # # id : integer # type : string # children_user_id: integer ... end class UserAdmin < User # Schema Information # # Table name: UserAdmin # # id : integer # special_field1 : string # special_field2 : string # ... ... end class UserCommon < User # Schema Information # # Table name: UserCommon # # id : integer # another_field1 : string # another_field2 : string # ... ... end I would like to know if, on creating an UserAdmin

Single Table Inheritance to refer to a child class with its own fields

↘锁芯ラ 提交于 2019-11-30 19:45:39
问题 I am using Ruby on Rails 3 and I implemented a working Single Table Inheritance like the following: class User < ActiveRecord::Base # Schema Information # # Table name: User # # id : integer # type : string # children_user_id: integer ... end class UserAdmin < User # Schema Information # # Table name: UserAdmin # # id : integer # special_field1 : string # special_field2 : string # ... ... end class UserCommon < User # Schema Information # # Table name: UserCommon # # id : integer # another

Rails devise registration form when having STI

南楼画角 提交于 2019-11-30 15:37:41
I dont know how to create a worker and a association. So i am able to link those together. I have a type colulm in user. This is my form(http://localhost:3000/workers/sign_up): <h2>Create Worker</h2> <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %> <%= devise_error_messages! %> <p><%= f.label :email %><br /> <%= f.text_field :email %></p> <p><%= f.label :kodeord %><br /> <%= f.password_field :password %></p> <p><%= f.label :bekraeft_kodeord %><br /> <%= f.password_field :password_confirmation %></p> <p><%= f.submit "Create" %></p> <% end %> <%=

Creating “feeds” from multiple, different Rails models

我们两清 提交于 2019-11-30 05:18:09
I'm working on an application that has a few different models (tickets, posts, reports, etc..). The data is different in each model and I want to create a "feed" from all those models that displays the 10 most recent entries across the board (a mix of all the data). What is the best way to go about this? Should I create a new Feed model and write to that table when a user is assigned a ticket or a new report is posted? We've also been looking at STI to build a table of model references or just creating a class method that aggregates the data. Not sure which method is the most efficient... You