Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hibernate column name issues

@Column(name="DateOfBirth") private Date dateOfBirth; 

I specifically need the above code to create a column named "DateOfBirth," instead Hibernate gives me a column named date_of_birth. How can I change this? Is there a web.xml property? I came across DefaultNamingStrategy and ImprovedNamingStrategy, but not sure how to specify one or the other.

like image 994
lucas Avatar asked Dec 17 '08 21:12

lucas


People also ask

Is @column annotation necessary?

Let's start with the @Column annotation. It is an optional annotation that enables you to customize the mapping between the entity attribute and the database column.

What is naming strategy in hibernate?

Implicit Naming StrategyHibernate uses a logical name to map an entity or attribute name to a table or column name. This name can be customized in two ways: it can be derived automatically by using an ImplicitNamingStrategy or it can be defined explicitly by using annotations.

What is @column in hibernate?

The @Column annotation is defined as a part of the Java Persistence API specification. It's used mainly in the DDL schema metadata generation. This means that if we let Hibernate generate the database schema automatically, it applies the not null constraint to the particular database column.


2 Answers

Try putting this in

application.properties

spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl 
like image 162
Rahul Singh Avatar answered Sep 29 '22 11:09

Rahul Singh


FYI: The reason for the insertion of underscores is probably because you're using an ImprovedNamingStrategy. It's set on your Configuration object. See here for an example...

If you don't want the underscores you can just not set the naming strategy, or set it to the DefaultNamingStrategy you discovered earlier.

like image 43
Dan Vinton Avatar answered Sep 29 '22 10:09

Dan Vinton