Changing naming strategy of @Table and @Column with EclipseLink to lower-case

雨燕双飞 提交于 2019-12-11 10:00:44

问题


When defining a JPA Entity like this:

@Entity
@Table
public class CaseExample implements Serializable {
    @Id
    Long id;
    @Basic
    String fooBar;
}

the automatically created SQL table name is "CASEEXAMPLE" and the column name "FOOBAR". How can I change that from upper-case to lower-case-with-underscore e.g. "case_example" and "foo_bar" without having to add a name="foo_bar" to every single @Table and @Column?

Is the naming strategy defined by JPA or implemenation dependend? I use JPA 2.0 with EclipseLink 2.5.0.


回答1:


JPA standardizes the names. I would leave them using the standard, or use @Column to change specific ones.

With EclipseLink you could modify you column names using your own code in a DescriptorCustomizer or SessionCustomizer. You would just iterate over your descriptor's mapping and reset the fieldNames based on your naming convention.



来源:https://stackoverflow.com/questions/18667089/changing-naming-strategy-of-table-and-column-with-eclipselink-to-lower-case

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!