0

I have something like this for defining the hibernate type mapping in the entity class:

@Entity
@Table(name = "TEST_TABLE")
public class Test {

     @Type( type = "jsonb" )
     @Column(name = "CONTENT_FILES")
     private List<ContentFile> contentFiles;

}

which map an entity field to a custom defined hibernate type jsonb for supporting PostgreSQL DB.

I would like to change the mapping to another hibernate custom type json for supporting MSSQL DB.

Can I support both mappings in the same entity class?

I tried to use the @Profile annotation but it doesn't work.

@Profile("pgsql")
@Type( type = "jsonb" )
@Profile("mssql")
@Type( type = "json" )
@Column(name = "CONTENT_FILES")
private List<ContentFile> contentFiles;
4
  • Are you planning to connect your application to two different databases at the same time ?@Peter Chau Commented Jul 2, 2019 at 11:03
  • That is why the JPA spec allows an orm.xml in which you can override these things for a specific database. Commented Jul 2, 2019 at 14:21
  • @LahiruWijesekara I would like to connect only one of the database, based on the profile settings. Commented Jul 3, 2019 at 9:42
  • You can try out below solution and share your results@PeterChau Commented Jul 4, 2019 at 11:33

1 Answer 1

1

json and jsonb both data types are almost identical according to the PostgreSQL documentation.Therefor you don't have to maintain two different data types to keep json in MSSQL and in PostgreSQL . Please refer to below link of PostgreSQL documentation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.