1

I'm having some thoubles with a generated column 'Text' type, in SQL Server. Same class anotations work fine when using PostgreSQL.

I tried:

@Lob
@Column(name = Columns.largeJsonText)
protected String largeJsonText;

and this:

@Lob
@Column(name = Columns.largeJsonText, length = 1048576)
protected String largeJsonText;

But both generate 'text' column type.

I'm using the following version of Eclipse Link:

        <groupId>org.eclipse.persistence</groupId>
        <artifactId>eclipselink</artifactId>
        <version>2.6.2</version>

Is it possible to generate a varchar(MAX) column for SQL Server? How? Thanks!

  • Have you tried specifying the columnDefinition="VARCHAR()"? This allows database specific column definitions to be used. You might try specifying the length value and removing the Clob annotation as well. Otherwise, you'll need to break into EclipseLink specific api to change the type returned for the Clob definition in the specific DatabasePlatform subclass used for your database. You can define your own subclass that overrides the value (see the buildFieldTypes method) or change it in a session customizer. – Chris Sep 19 '16 at 15:16
  • Ok, that is what I needed. I couldn't find the right documentation. Could you please provide a link to go deep in the topic? Thanks! – Simon De Uvarow Sep 20 '16 at 11:10

1 Answers1

2

The correct way to create with JPA and SQL Server is:

@Column(name = "fieldName", columnDefinition = "VARCHAR(1337)")
private String someString;

https://stackoverflow.com/a/43457020/5626568

Community
  • 1
  • 1
ℛɑƒæĿᴿᴹᴿ
  • 4,983
  • 4
  • 38
  • 58
  • varchar(MAX)... "max" is not a placeholder for a real number value. varchar(MAX) (no subsitutions) is a datatype in sql server. this answer unforunately is not helpfu. I'm not going to downvote it, but am making the point for future readers. https://learn.microsoft.com/en-us/sql/t-sql/data-types/char-and-varchar-transact-sql?view=sql-server-2017 – granadaCoder Mar 06 '19 at 21:04
  • The columnDefinition value will be database specific. For example for PostgreSQL you could use the value "character varying" or "text". – Jeff S. Nov 22 '21 at 17:03