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?
As we saw above, JPA is a standard for defining the persistence layer and Spring Data JPA is a sub-project under the Spring Framework umbrella which allows Spring applications to integrate with JPA.
The main advantage of JPA over JDBC for developers is that they can code their Java applications using object-oriented principles and best practices without having to worry about database semantics.
In JPA the object id is defined through the @Id annotation and should correspond to the primary key of the object's table. An object id can either be a natural id or a generated id. A natural id is one that occurs in the object and has some meaning in the application.
You need to use the columnDefinition property of the @Column annotation. i.e.
@Column(columnDefinition="varchar2(20)")
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With