0

All attributes within my persistence unit which have the type "MyCar" should be mapped to the same database column type "VARCHAR(255)". At the moment I have to set the @Column annotation to each and every attribute as follows:

@Column(columnDefinition = "VARCHAR(255)")
private MyCar car1;

@Column(columnDefinition = "VARCHAR(255)")
private MyCar car2;

@Column(columnDefinition = "VARCHAR(255)")
private MyCar car3;
...

Is there any way to set the columnDefinition for "MyCar" globally?

Chilly Code
  • 678
  • 2
  • 6
  • 17
  • 1
    MyCar is also an Entity? – Matteo Baldi Apr 08 '16 at 21:46
  • Good question! I forgot to mention it. No, MyCar is not an Entity. It is a custom Java class which gets converted to a String using a JPA converter class, annotated with javax.persistence.Converter: "@Converter(autoApply = true)". The converter class implements AttributeConverter – Chilly Code Apr 09 '16 at 08:24
  • How are you adding the converter? EclipseLink also has session customizers that you can use to programmatically go through all the entity mappings and set the column for any that use a MyCar type. see http://stackoverflow.com/questions/19896352/customize-jpa-field-name-mapping-using-eclipselink and https://wiki.eclipse.org/Customizing_the_EclipseLink_Application_(ELUG) – Chris Apr 11 '16 at 14:36

0 Answers0