I have a spring boot project that runs with this setup:
@SpringBootApplication(exclude=SecurityAutoConfiguration.class)
@ImportResource("classpath:/application-context.xml")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
I discovered hibernate was mapping my atributes without converting camelCase to SNAKE_CASE, instead, it was just applying upper_case to it (since Oracle is case insensitive, it doesn't matter):
Caused by: java.sql.SQLException: ORA-00904: "PESSOA0_"."IDPESSOA": invalid identifier
Here's my entity:
@Entity
@Table(name = "BC_PESSOA")
@NamedQuery(name = "Pessoa.findAll", query = "SELECT p FROM Pessoa p")
public class Pessoa implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private Long idPessoa;
I wanted hibernate to implicitly map idPessoa attribute to ID_PESSOA column, as it's default behavior. I don't know why this isn't happening.
I have tons of other entities with 30-40 attributes (I know it's bad practice, but I'm not allowed to change it into smaller objects) and I wanted to leave the objects mapping responsibility completely to hibernate. I know I could use Eclipse's JPA facet to create mapped entities with database but I'm really curious to understand why the standard behavior isn't standard anymore.
At application-context.xml
, I have this piece of code showing some beans configuration(covered private names):
I used xirulei
as a dummy configuration to see any errors, but none appeared, only the same behavior as before. Changing my dialect although actually broke spring, if it matters.
EDIT
I discovered my project is using spring boot 1.4.5.RELEASE but due other non debatable reasons Hibernate is 4.2.19.FINAL. Looking here I saw this piece:
before adding mappings:
SessionFactory sf = new Configuration()
.setNamingStrategyDelegator(ImprovedNamingStrategyDelegator.DEFAULT_INSTANCE)
.addFile("Item.hbm.xml")
.addFile("Bid.hbm.xml")
.buildSessionFactory();
Knowing I'm using application-context.xml
to configure spring/jpa/hibernate, where does 'before adding mappings' should be? Should I use SpringNamingStrategy (as old spring) or hibernate.ejb.naming_strategy? And besides that, which values would be valid?