We're updating the issue view to help you get more done. 

Better handling of implicit column naming with @ElementCollection of @Embeddables

Description

DefaultComponentSafeNamingStrategy is incompatible with @ElementCollection of @Embeddable objects.

Given the following classes

1 2 3 4 5 6 7 8 9 10 11 12 @Entity public class Foo { @ElementCollection private List<Bar> bars; ... } @Embeddable public class Bar { private String name; ... }

and DefaultComponentSafeNamingStrategy as a naming strategy, Hibernate generates the schema with the following incorrect table:

create table Foo_bars (Foo_id bigint not null, bars_collection&&element_name varchar(255))

.collection&&element. is an internal placeholder that should be removed before use of property name. Other naming strategies effectively remove it by using the part of property name after the last ., but DefaultComponentSafeNamingStrategy doesn't, it just replaces . with _.

Here is a workaround:

1 2 3 4 5 6 public class FixedDefaultComponentSafeNamingStrategy extends DefaultComponentSafeNamingStrategy { @Override public String propertyToColumnName(String propertyName) { return super.propertyToColumnName(propertyName.replace(".collection&&element.", ".")); } }

Environment

None

Status

Assignee

Steve Ebersole

Reporter

Artem Troitskiy

Components

Fix versions

Affects versions

3.5.0-Final

Priority

Minor