How to Tell JPA the prefered DataType

你。 提交于 2019-12-04 16:16:36

问题


If I use JPA (EclipseLink) to create tables a String type results in a varchar2(255). How could I tell JPA (via Annotation) to create a varchar2(20) attribute.

If I have a List JPA creates a BLOB(4000) but I would like a varchar2 (my serialized object's string is short)

How is this possible? Do I have to do it by hand?


回答1:


You need to use the columnDefinition property of the @Column annotation. i.e.

@Column(columnDefinition="varchar2(20)")



回答2:


If I use JPA (EclipseLink) to create tables a String type results in a varchar2(255). How could I tell JPA (via Annotation) to create a varchar2(20) attribute.

Using the columnDefinition can break portability from one database to another. For a string-valued column, prefer using the length element (which defaults to 255):

@Column(length=20)
String someString;



回答3:


You can set the length on your @Column annotation, as such:

@Column(length = 20)

Note that length is only for text columns. For numeric, you can use precision and scale.




回答4:


@Column(name = "doc_number", columnDefinition = "varchar2(20)")

Please, try that.



来源:https://stackoverflow.com/questions/4088400/how-to-tell-jpa-the-prefered-datatype

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