0

There are 2 tables that are mapped to 1 class. This works but when I want to update the object I don't know from which table it came. Is there a way to store or get the entity name?

Mapping:

<hibernate-mapping>
   <class name="model.object.ObjectAttributeType" table="OBJECTPARAMETERTYPE" entity-name="OBJECTPARAMETERTYPE">
     ...
   </class>
   <class name="model.object.ObjectAttributeType" table="OBJECTPROPERTYTYPE" entity-name="OBJECTPROPERTYTYPE">
      ...
   </class>
</hibernate-mapping>
ThijsJ
  • 1
  • 2

1 Answers1

2

You can define 2 classes

public class ParameterObjectAttributeType extends ObjectAttributeType
public class PropertyObjectAttributeType extends ObjectAttributeType

and map the different classes to 2 different tables

StanislavL
  • 56,971
  • 9
  • 68
  • 98
  • Yeah that's an option, but than the subclasses will be totally empty. And I would work only if could set a variable trough hbm or get the entity name. – ThijsJ Jan 16 '15 at 14:33
  • This answer is correct, you would just have to update your hbm's to map to the subclasses rather than the super classes. I would argue that you are using hibernate incorrectly, there shuld generally be a one to one mapping between database tables and java entities. Think of it in terms of single responsibility, it dosent make sense to hold two different sets of data in the same object. Thats essentially why you have two tables to begin with! – ConMan Jan 16 '15 at 15:07