single-table-inheritance

How to get the DiscriminatorValue at run time

痞子三分冷 提交于 2019-11-27 02:06:01
问题 We have the following classes @Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) // optional annotation as this is default @DiscriminatorColumn(name = "apType", discriminatorType = DiscriminatorType.STRING, length = 255) @DiscriminatorValue("AP") public class ApplicationProcess { } And this @Entity @DiscriminatorValue("APS") public class ApplicationProcessScheme extends ApplicationProcess { } Now I need to know at runtime if the ApplicationProcess is of DiscriminatorValue AP or APS

Rails — use type column without STI?

眉间皱痕 提交于 2019-11-26 07:29:43
问题 I want to use a column called type without invoking Single Table Inheritance (STI) - I just want type to be a normal column that holds a String . How can I do this without having Rails expecting me to have single table inheritance and throwing an exception of The single-table inheritance mechanism failed to locate the subclass...This error is raised because the column \'type\' is reserved for storing the class in case of inheritance. ? Any ideas on how to do this? 回答1: In Rails 3.1 set