-1

I have a repository method like

@Query("from Application app where app.id.hostId = :hostId")
List<Application> getApplicationsByApplicationId(@Param("hostId") String hostId);

And my domain class reads something like

public class Application {

    @EmbeddedId
    Composite id;
     ...
     ...

    @Embeddable
    public static class Composite implements java.io.Serializable {
        @Column(name = "id")
        private String id;

        @Column(name = "hostId")
        private String hostId; 
        ....

Somewhere down the processing chain, hostIdstring gets transformed to host_id, So I get an error like

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'application0_.host_id' in 'field list'.

I am trying to migtate an existing hibernate / JPA layer into Spring Boot JPA. Any pointers will be greatly appreciated.

Sathyakumar Seshachalam
  • 2,013
  • 3
  • 20
  • 32
  • Try add `@Access(AccessType.FIELD)` annotation for `Composite` class. And make `Composite` class not inner. Also how column `host_id` named in the table? – HAYMbl4 Apr 25 '16 at 10:20
  • Its the same error with the prescribed changes. The column in DB is named as `hostid` in table. – Sathyakumar Seshachalam Apr 25 '16 at 10:45
  • may be dublicate http://stackoverflow.com/questions/25283198/spring-boot-jpa-column-name-annotation-ignored – HAYMbl4 Apr 25 '16 at 11:03

2 Answers2

0

Use:

@Column(name = "hostid")

notice that all are lowercase.

luboskrnac
  • 23,973
  • 10
  • 81
  • 92
0

This is caused by the Hibernate naming strategy. The default strategy transforms camel case in Java to _ in database.

If you don't want this behavior use JPA default. You can set it in application.properties:

spring.jpa.hibernate.naming_strategy: org.hibernate.cfg.EJB3NamingStrategy
Simon Martinelli
  • 34,053
  • 5
  • 48
  • 82