I have a table with two fields I would like to have two objects.
First one only has field1
@Entity(name = \"simpleTableObject\")
@Table(name = \"someTabl
You can have a common superclass for both entities:
@MappedSuperclass
public abstract class AbstractTableObject {
// common mappings
}
@Entity
@Table(name = "someTable")
public class TableObject extends AbstractTableObject {
// remaining mappings
}
@Entity
@Table(name = "someTable")
@Immutable
public class SimpleTableObject extends AbstractTableObject {
// nothing here
}
Additionally, you can mark the SimpleTableObject
entity to be @Immutable as shown above, so that it cannot be persisted or updated accidentally.