mappedsuperclass

Can I use @MappedSuperclass annotation on an interface?

烂漫一生 提交于 2019-12-01 20:20:59
I want to group common mappings in an interface , but I cannot use an abstract superclass because my entities already extend another class . So I need an interface like below: @MappedSuperclass public interface NamedEntity { @Column(name = "name") String getName(); void setName(String name); } and I want to use it like below: public class Person { private Long id; private String name; public Long getId(){ return id; } public void setId(Long id){ this.id = id; } public String getName() { return name; } public void setName(String name){ this.name = name; } } @Entity @Table(name = "person_entity"

Doctrine2: OneToMany on mapped superclass

流过昼夜 提交于 2019-12-01 01:10:09
问题 My DB structure is as follows: work: CTI table Work MappedSuperclass table AbstractImageWork which extends Work final table PhotoWork which extends AbstractImageWork comment: MappedSuperclass table Comment final table WorkComment which extends Comment WorkComment has a ManyToOne relation to Work : @ManyToOne(targetEntity="Work", inversedBy="comments") Work has a OneToMany relation to WorkComment : @OneToMany(targetEntity="WorkComment", mappedBy="work") The problem is that Doctrine gives me

Hibernate: how to fetch only not-logically deleted objects

女生的网名这么多〃 提交于 2019-11-28 08:03:19
问题 Nearly every table in our database has a FK to the Auditing table which logs created, updated and deleted status (date and username). We mapped the auditing table to the Auditing class and use it like this: @MappedSuperclass public class BusinessObject extends DataObject { private static final long serialVersionUID = -1147811010395941150L; @OneToOne(fetch = FetchType.EAGER, cascade = { CascadeType.ALL }) @JoinColumn(name = "AUD_ID") private AuditingObject auditing; ... As you'd expect, nearly

MappedSuperclass - Change SequenceGenerator in Subclass

一曲冷凌霜 提交于 2019-11-27 09:01:22
I'm using JPA2 with Hibernate and try to introduce a common base class for my entities. So far it looks like that: @MappedSuperclass public abstract class BaseEntity { @Id private Long id; @Override public int hashCode() { // ... } @Override public boolean equals(Object obj) { // ... } public Long getId() { return this.id; } public void setId(Long id) { this.id = id; } } However, for every table theres a sequence $entityname_seq which I want to use as my sequence generator. How can I set that from my subclass? I think I need to override @GeneratedValue and create a new SequenceGenerator with

Hibernate : How override an attribute from mapped super class

左心房为你撑大大i 提交于 2019-11-26 20:21:37
The generic entity, super class: @MappedSuperclass public abstract class GenericEntity { private Integer id; public Integer getId() {return id;} public void setId(Integer id) {this.id = id;} } The pojo: @Entity @Table(name = "POJO_ONE") @SequenceGenerator(name = "HB_SEQ_POJO_ONE", sequenceName = "SEQ_POJO_ONE", allocationSize = 1) public class PojoOne extends GenericEntity { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "HB_SEQ_POJO_ONE") @Column(name = "ID") @AttributeOverride(name = "id", column = @Column(name = "ID")) private Integer id; @Override public Integer getId(

MappedSuperclass - Change SequenceGenerator in Subclass

徘徊边缘 提交于 2019-11-26 11:20:39
问题 I\'m using JPA2 with Hibernate and try to introduce a common base class for my entities. So far it looks like that: @MappedSuperclass public abstract class BaseEntity { @Id private Long id; @Override public int hashCode() { // ... } @Override public boolean equals(Object obj) { // ... } public Long getId() { return this.id; } public void setId(Long id) { this.id = id; } } However, for every table theres a sequence $entityname_seq which I want to use as my sequence generator. How can I set

Hibernate : How override an attribute from mapped super class

无人久伴 提交于 2019-11-26 09:02:08
问题 The generic entity, super class: @MappedSuperclass public abstract class GenericEntity { private Integer id; public Integer getId() {return id;} public void setId(Integer id) {this.id = id;} } The pojo: @Entity @Table(name = \"POJO_ONE\") @SequenceGenerator(name = \"HB_SEQ_POJO_ONE\", sequenceName = \"SEQ_POJO_ONE\", allocationSize = 1) public class PojoOne extends GenericEntity { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = \"HB_SEQ_POJO_ONE\") @Column(name = \"ID\")