0

I have a Class whose objects I want to be able to persist via Hibernate such as:

package my.package
@Entity
@Table(name="hibernatedclass")
public class HibernatedClass {

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

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

    [....]
}

As it can be seen the name I have given the table to store the objects of my.package.HibernatedClass is named hibernatedclass.

What I am looking for in an answer is: How can this naming be automatized? Something that would imho look similar to this pseudo-code.

@Table(name=class.getCanonicalName())
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
humanityANDpeace
  • 4,350
  • 3
  • 37
  • 63
  • By default, if the `name ` attribute is not specified, it uses the simple class name of the current class as table name . So why not simply declare `@Table` ? – davidxxx Jun 05 '17 at 10:43
  • The simple class name of the current class will be used by default even if `@Table` is not declared. Are you seeing a different behavior? – crizzis Jun 05 '17 at 10:50
  • 1
    @crizzis Sorry, you are both of course right. I have tested the described behaviour and it really defaults to the value. Anything I could wish for is hence alrady there. Any improvement to the naming, i..e ot include a prefix or the canonical(withpackage) classname can be done wit something like provided in the answers to https://stackoverflow.com/questions/4313095/jpa-hibernate-and-custom-table-prefixes . So in principle my question is kind of a duplicate. Should I delete? – humanityANDpeace Jun 05 '17 at 11:25

0 Answers0