1

In my primary Entity I have two instances of an embeddable type like this:

@Embeddable
public class VariableDate {
    protected Instant value;
    protected CustomEnum type;
}

@Entity
public class MyEntity {
    protected VariableDate begin;
    protected VariableDate end;
}

This yields the following exception:

Caused by: org.hibernate.MappingException: 
    Repeated column in mapping for entity: de.company.MyEntity column: value 
    (should be mapped with insert="false" update="false")

According to this SO response I need to specify the naming strategy:

org.hibernate.cfg.DefaultComponentSafeNamingStrategy

I tried specifying the naming strategy in my application.properties according to the Spring Boot documentation:

spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.cfg.DefaultComponentSafeNamingStrategy
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.cfg.DefaultComponentSafeNamingStrategy

I tested all combinations (both at the same time, each individually and none), unfortunately I receive above mentioned exception in any case.

The remaining database configuration from application.properties:

spring.datasource.url=jdbc:mysql://localhost:3306/database?useUnicode=true&characterEncoding=UTF-8
spring.datasource.username=user
# password provided by external configuration
# spring.datasource.password=password
spring.datasource.testWhileIdle=true
spring.datasource.validationQuery=SELECT 1
spring.jpa.show-sql=false
# Hibernate ddl auto (create, create-drop, update, validate)
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

The dependencies are based on Spring Boot 1.5.2:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.2.RELEASE</version>
</parent>

A valid outcome would be storing the values in columns like begin_value, begin_type, end_value, end_type in the table for MyEntity.

Edit: The correct solution was posted here already: https://stackoverflow.com/a/43412964/3388491

Community
  • 1
  • 1
oschlueter
  • 2,596
  • 1
  • 23
  • 46
  • Is there any log statement about naming strategy? Sometimes hibernate "warns" you that what you have asked for won't work, but it still tries to instantiate itself. – TheNorthWes Apr 14 '17 at 15:48
  • I must've tried Farrukh's solution in the wrong application.properties... Anyway this is the correct solution: http://stackoverflow.com/a/43412964/3388491 – oschlueter Apr 18 '17 at 11:59
  • Possible duplicate of [Automatically Add a Prefix to Column Names for @Embeddable Classes](http://stackoverflow.com/questions/3046677/automatically-add-a-prefix-to-column-names-for-embeddable-classes) – oschlueter Apr 18 '17 at 11:59

0 Answers0