I am trying since longer time to generated abstract/concrete annotated pojo pairs. Hope you guys can help me with my problem.
What i try to achieve:
- HibernateTools should generate a class pair (abstract/concrete) for each mySQL table.
- The abstract class should contain all relations, fields, ids and unique constraints (everything with annotations)
- The concrete class should be empty and inherit from the base class
First of all I am looking for an solution about how I have to set the annotations correctly (@MappedSuperclass, @Table, @Entity, @Inheritance(strategy = InheritanceType.XXX))
I tried several variations, but nothing seems to work for me.
If this would work, I am looking for a solution about how to auto generate those pojo pairs with correct annotations.
I am using Hibernate 4 and Hibernate Tools Eclipse Plugin for Kepler.
Is it possible to achieve this without using *.hbmxml files? (only annotations)
Something like this (https://hibernate.atlassian.net/browse/HB-874), but I was not able to access those <codegen> properties in hibernate 4.
Example:
MySQL Table: EMPLOYEE
Abstract base class:
Code:
/**
* Employee generated by hbm2java
*/
@Entity
@Table(name = "employee", catalog = "test", uniqueConstraints = @UniqueConstraint(columnNames = "E_MAIL"))
public abstract class EmployeeBase implements java.io.Serializable {
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "ID", unique = true, nullable = false)
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "TEAM_ID", nullable = false)
public Team getTeam() {
return this.team;
}
}
Concrete class:
Code:
public class Employee extends EmployeeBase {
}