Pregunta

I am using hbm2ddl to autocreate the schema by including this line in configuration:

<prop key="hibernate.hbm2ddl.auto">create</prop>

I have a entity bean defined as:

@Entity
@Table(name = "user")
public class User {

    @Column(name = "firstname")
    private String firstName;

    @Column(name = "lastname")
    private String lastName;

    private String fullName;

}

There are 3 attributes and I like the first two to be saved in database table and like to compute the third one. When I run hbm2ddl with option as create it's creating all 3 columns although I don't have @Column annotation on the third one.

How can I prevent Hibernate from creating the last attribute as a column?

¿Fue útil?

Solución

@Transient would definitely stop it.

Otros consejos

The @Column annotation doesn't mean that the field is going to be persisted. It just adds more information e.g. for the schema generator.

If you don't want a field to be persisted (and still, you use field access for your entities), you should either annotate it as @Transient as NimChimpsky pointed, or use Java transient keyword.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top