1

I found this solution, that doesn't solve the problem. In JPA we can do this:

@MappedSuperclass
public class BasicEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(updatable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date created = new Date();

    @Temporal(TemporalType.TIMESTAMP)
    private Date modified = new Date();
}

@Entity
public class User extends BasicEntity {

    private String username;
    private String password;
}

Then, hibernate.hbm2ddl.auto generates one table with all inherited columns and this is exactly what I want:

user (
    id,
    created,
    modified,

    username,
    password,
)

In Grails I do this

abstract class BasicEntity {

    static mapping = {
        tablePerSubclass true
    }

    Date dateCreated
    Date lastUpdated
}

class User extends BasicEntity {

    String username
    String password
}

And it generates me two tables with no inheritance

basic_entity (
    id,
    version,
    date_created,
    last_updated,
)

user (
    id,
    username,
    password,
)
4

0 回答 0