문제

I am working under play framework 2.2.1 and I need a quick blob saving entity in my data model (a quick user settings documents that needs to be saved for the client side). I have done that many time but this time I would like Ebean to take care of the grunt work for me.

I would like to make Ebean recognize jackson's JsonNode and ObjectNode as column types. Here is what my class looks like:

@Entity
public class UserSettings extends Model {

    @Id
    @GeneratedValue
    private Long id;

    private JsonNode blob;

    // [... getters setters and whatnot ...]
}

I would like Ebean to directly create a TEXT column in my table (using PostgreSQL) and parse and stringify the column when needed automatically. I have not found code examples or documentation relating to this kind of features. This looks so basic it should be possible. Or am I really wrong? Ebean already supports joda time, it would seem weird it cannot support adding custom object types or json blobs, right?

도움이 되었습니까?

해결책

You can have a look at: com.avaje.ebean.config.ScalarTypeConverter

or alternatively com.avaje.ebeaninternal.server.type.ScalarTypeBaseVarchar

and perhaps as some examples to work off...

com.avaje.ebeaninternal.server.type.ScalarTypeUUID com.avaje.ebeaninternal.server.type.ScalarTypeClob

The first question is whether you are storing the JSON as Clob or Varchar (or perhaps you need 2 different options).

Update: As of Ebean ORM version 4.6.3 there is now built in support for storing both JsonNode and Map<String,Object> into various database types (Clob,Varchar,Blob plus Postgres JSON and JSONB data types).

Refer to:

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top