Posjsonhelper Libraryは、PostgreSQL JSON関数のHibernateクエリのサポートを追加するオープンソースプロジェクトです。ライブラリは、PostgreSQLテキスト検索関数のサポートもあります。テキスト検索コンポーネントの使用方法について詳しく知るには、テキストモジュールの指示を確認してください。ライブラリは、Javaプログラミング言語で書かれています。この瞬間のプロジェクトは、バージョン5と6の冬眠をサポートします。Javaの必要なバージョンは、Hibernate 5のサポートに少なくともバージョン8、Hibernate 6のバージョン11です。
このプロジェクトは、Central Mavenリポジトリで入手できます。 Project Descriptorファイル(pom.xml)の依存関係として追加するだけで使用できます。
Hibernate 5の場合:
< dependency >
< groupId >com.github.starnowski.posjsonhelper</ groupId >
< artifactId >hibernate5</ artifactId >
< version >0.4.2</ version >
</ dependency >Hibernate 6の場合:
< dependency >
< groupId >com.github.starnowski.posjsonhelper</ groupId >
< artifactId >hibernate6</ artifactId >
< version >0.4.2</ version >
</ dependency >Posjsonhelperライブラリには、冬眠ライブラリへの一時的な依存関係がありません。したがって、以下のように、あなたのプロジェクトでHibernateの依存関係を分離する必要があることに留意してください。
< dependency >
< groupId >org.hibernate</ groupId >
< artifactId >hibernate-core</ artifactId >
< version >????</ version >
</ dependency >Hibernate互換性バージョンマトリックスを確認して、正しいバージョンを確認してください。
JSON操作に関連する一部の機能のデフォルト実装では、org.json:JSONライブラリが必要です。ただし、特定のインターフェイスを実装する方法があり、下のライブラリを追加する必要はない場合があります。
< dependency >
< groupId >org.json</ groupId >
< artifactId >json</ artifactId >
< version >20240303</ version >
</ dependency >誰かがソースからローカルにプロジェクトを構築したい場合は、Pribunting.mdファイルを参照して、プロジェクトをローカルにセットアップする方法を確認してください。
重要!このセクションは、Hibernate 5にのみ有効です。プロジェクトでPosjsonhelperライブラリを使用できるようにするには、正しい冬眠方言を指定する必要があります。ライブラリは、すでに存在しているラッパーをほとんど実装していません。
方言は、hibernate構成ファイルで設定する必要があります。
<? xml version = " 1.0 " encoding = " UTF-8 " ?>
< hibernate-configuration xmlns = " http://www.hibernate.org/xsd/orm/cfg " >
< session-factory >
< property name = " hibernate.dialect " >com.github.starnowski.posjsonhelper.hibernate5.dialects.PostgreSQL95DialectWrapper</ property >
...または、たとえば、Spring Framework構成プロパティファイルで:
...
spring.jpa.properties.hibernate.dialect =com.github.starnowski.posjsonhelper.hibernate5.dialects.PostgreSQL95DialectWrapper
...既に冬眠方言の種類を拡張するタイプがあり、プロジェクトに必要な場合。 Postgresqldialectenricherコンポーネントを使用するように、タイプに調整を追加します。
import com . github . starnowski . posjsonhelper . hibernate5 . PostgreSQLDialectEnricher ;
import org . hibernate . dialect . PostgreSQL95Dialect ;
public class PostgreSQLDialectWithDifferentSchema extends PostgreSQL95Dialect {
public PostgreSQLDialectWithDifferentSchema () {
PostgreSQLDialectEnricher enricher = new PostgreSQLDialectEnricher ();
enricher . enrich ( this );
}
}重要!このセクションは、Hibernate 6にのみ有効です。Hibernate6を使用するプロジェクトでPosjsonhelperライブラリを使用するには、指定されたorg.hibernate.boot.model.functioncontributorの実装が必要です。ライブラリには、このインターフェイスの実装があります。つまり、com.github.starnowski.posjsonhelper.hibernate6.posjsonhelperfunctionContributorです。
この実装を使用するには、「org.hibernate.boot.model.functionContributor」という名前のファイルを作成する必要があります。
別のソリューションは、アプリケーションの起動時にcom.github.starnowski.posjsonhelper.hibernate6.sqmfunctionregistryenricherコンポーネントを使用することです。スプリングフレームワークの使用法の以下の例のように。
import com . github . starnowski . posjsonhelper . hibernate6 . SqmFunctionRegistryEnricher ;
import jakarta . persistence . EntityManager ;
import org . hibernate . query . sqm . NodeBuilder ;
import org . springframework . beans . factory . annotation . Autowired ;
import org . springframework . context . ApplicationListener ;
import org . springframework . context . annotation . Configuration ;
import org . springframework . context . event . ContextRefreshedEvent ;
@ Configuration
public class FunctionDescriptorConfiguration implements
ApplicationListener < ContextRefreshedEvent > {
@ Autowired
private EntityManager entityManager ;
@ Override
public void onApplicationEvent ( ContextRefreshedEvent event ) {
NodeBuilder nodeBuilder = ( NodeBuilder ) entityManager . getCriteriaBuilder ();
SqmFunctionRegistryEnricher sqmFunctionRegistryEnricher = new SqmFunctionRegistryEnricher ();
sqmFunctionRegistryEnricher . enrich ( nodeBuilder . getQueryEngine (). getSqmFunctionRegistry ());
}
}Posjsonhelperライブラリを使用するには、JSONオペレーターを実行するいくつかのSQL関数を作成する必要があります。一部のJSONオペレーターは、逃げなければならないため、冬眠によって実行できません。デフォルトの構成の場合、ライブラリは以下の関数を作成する必要があります。
CREATE OR REPLACE FUNCTION jsonb_all_array_strings_exist (jsonb, text []) RETURNS boolean AS $$
SELECT $ 1 ?& $ 2 ;
$$ LANGUAGE SQL;
CREATE OR REPLACE FUNCTION jsonb_any_array_strings_exist (jsonb, text []) RETURNS boolean AS $$
SELECT $ 1 ?| $ 2 ;
$$ LANGUAGE SQL;生成されたDDLステートメントは、統合テスト中に実行することも、リキバーゼやフライウェイなどのデータベースに変更を適用するツールで使用できます。重要!同様の関数を使用する必要があるが、異なる名前がある場合、これはアプリケーションプロパティで指定する必要があります。 ["Postgresql方言を添付する方法"](#How-to-attach-postgresql方言)セクションで言及されている冬眠方言の種類が延長されるため、必要があります。ただし、そのようなプロパティを異なる方法で渡す必要がある場合に備えて、Postgresqldialectenricherタイプにはコンテキストオブジェクトを渡す方法もあります(コアコンテキストと冬眠コンテキストを確認してください)
コンテキストクラスは、ライブラリが使用する関数の名前を保持します。方言クラスは、システムプロパティに基づいてコンテキストオブジェクトを生成するCoreContextPropertiessupplierコンポーネントを使用します。
DatabaseOperationExecutorFacadeタイプを使用して、プログラムでDDLを追加することも可能です。以下に、Spring FrameworkコンテキストでアプリケーションにDDLの変更を適用する方法の例を示します。
import com . github . starnowski . posjsonhelper . core . Context ;
import com . github . starnowski . posjsonhelper . core . DatabaseOperationExecutorFacade ;
import com . github . starnowski . posjsonhelper . core . DatabaseOperationType ;
import org . springframework . beans . factory . annotation . Autowired ;
import org . springframework . context . ApplicationListener ;
import org . springframework . context . annotation . Configuration ;
import org . springframework . context . event . ContextRefreshedEvent ;
import javax . sql . DataSource ;
@ Configuration
public class SQLFunctionsConfiguration implements
ApplicationListener < ContextRefreshedEvent > {
@ Autowired
private Context context ;
@ Autowired
private DataSource dataSource ;
@ Override
public void onApplicationEvent ( ContextRefreshedEvent contextRefreshedEvent ) {
DatabaseOperationExecutorFacade facade = new DatabaseOperationExecutorFacade ();
try {
facade . execute ( dataSource , context , DatabaseOperationType . LOG_ALL );
facade . execute ( dataSource , context , DatabaseOperationType . CREATE );
facade . execute ( dataSource , context , DatabaseOperationType . VALIDATE );
} catch ( Exception e ) {
throw new RuntimeException ( "Error during initialization of sql functions for jsonb type operations" , e );
}
}
}DatabaseOperationExecutorFacadeオブジェクトで実行できる操作がいくつかあります
| プロパティ名 | 説明 |
|---|---|
| 作成する | DDLの変更をデータベースに適用します |
| 検証します | DDLの変更がデータベースに適用されたかどうかを検証します |
| 落とす | データベースにDDLの変更をドロップします |
| log_all | 操作を作成、検証、ドロップするためのDDLスクリプトを表示します |
簡単に説明するために、JSONBタイプを保存する1つの列のデータベーステーブルがあると仮定します。
create table item (
id int8 not null ,
jsonb_content jsonb,
primary key (id)
)この表では、以下の例のように、任意のJSONで行を挿入できます。
INSERT INTO item (id, jsonb_content) VALUES ( 1 , ' {"top_element_with_set_of_values":["TAG1","TAG2","TAG11","TAG12","TAG21","TAG22"]} ' );
INSERT INTO item (id, jsonb_content) VALUES ( 2 , ' {"top_element_with_set_of_values":["TAG3"]} ' );
-- item without any properties, just an empty json
INSERT INTO item (id, jsonb_content) VALUES ( 6 , ' {} ' );
-- int values
INSERT INTO item (id, jsonb_content) VALUES ( 7 , ' {"integer_value": 132} ' );
-- double values
INSERT INTO item (id, jsonb_content) VALUES ( 10 , ' {"double_value": 353.01} ' );
INSERT INTO item (id, jsonb_content) VALUES ( 11 , ' {"double_value": -1137.98} ' );
-- enum values
INSERT INTO item (id, jsonb_content) VALUES ( 13 , ' {"enum_value": "SUPER"} ' );
-- string values
INSERT INTO item (id, jsonb_content) VALUES ( 18 , ' {"string_value": "the end of records"} ' );ほとんどの述語コンポーネントは、Hibernate Contextオブジェクトを使用します。ほとんどの場合、プロジェクトで使用されている冬眠機能名の名前を保持しています。方言クラスとfunctionContributorタイプは、システムプロパティに基づいてHibernateContextオブジェクトを生成するHibernateContextPropertiessupplierコンポーネントを使用します。 psojsonhelperオペレーターのデフォルトのHQL関数名を変更する必要がない場合は、以下のようにビルダーコンポーネントによって作成されたhibernateContextを使用することさえあります。
HibernateContext hibernateContext = HibernateContext . builder (). build ();「jsonb_extract_path」は、「text []」(#> operatorに相当)として渡されたパス要素によって指されたJSONB値を返すpostgreSQL関数です。多くの関数が実行に「jsonb」タイプを使用するため、これは便利です。詳細については、PostgreSQLドキュメントを確認してください。 Hibernate 5例:以下に、JSONコンテンツプロパティ「TOP_ELEMENT_WITH_SET_OF_VALUES」に正確な値のセットが含まれるアイテムオブジェクトのリストを返す方法の例があります。この例では、jsonballarraysstringsexistpredicateを使用しています。
@ Autowired
private HibernateContext hibernateContext ;
@ Autowired
private EntityManager entityManager ;
public List < Item > findAllByAllMatchingTags ( Set < String > tags ) {
CriteriaBuilder cb = entityManager . getCriteriaBuilder ();
CriteriaQuery < Item > query = cb . createQuery ( Item . class );
Root < Item > root = query . from ( Item . class );
query . select ( root );
query . where ( new JsonbAllArrayStringsExistPredicate ( hibernateContext , ( CriteriaBuilderImpl ) cb , new JsonBExtractPath (( CriteriaBuilderImpl ) cb , singletonList ( "top_element_with_set_of_values" ), root . get ( "jsonbContent" )), tags . toArray ( new String [ 0 ])));
return entityManager . createQuery ( query ). getResultList ();
}上記の方法では、HibernateがHQLクエリを実行します。
select
generatedAlias0
from
Item as generatedAlias0
where
jsonb_all_array_strings_exist( jsonb_extract_path( generatedAlias0 . jsonbContent , :param0 ) , json_function_json_array(:param1)) = TRUEネイティブSQLは以下のフォームを使用する予定です。
select
item0_ . id as id1_0_,
item0_ . jsonb_content as jsonb_co2_0_
from
item item0_
where
jsonb_all_array_strings_exist(jsonb_extract_path( item0_ . jsonb_content ,?), array[?]) = true詳細については、テストで使用されているDAOを確認してください。
Hibernate 6例:
以下には、上記と同じ例がありますが、冬眠6の場合。
import org . hibernate . query . sqm . NodeBuilder ;
....
@ Autowired
private HibernateContext hibernateContext ;
@ Autowired
private EntityManager entityManager ;
public List < Item > findAllByAllMatchingTags ( Set < String > tags ) {
CriteriaBuilder cb = entityManager . getCriteriaBuilder ();
CriteriaQuery < Item > query = cb . createQuery ( Item . class );
Root < Item > root = query . from ( Item . class );
query . select ( root );
query . where ( new JsonbAllArrayStringsExistPredicate ( hibernateContext , ( NodeBuilder ) cb , new JsonBExtractPath ( root . get ( "jsonbContent" ), ( NodeBuilder ) cb , singletonList ( "top_element_with_set_of_values" )), tags . toArray ( new String [ 0 ])));
return entityManager . createQuery ( query ). getResultList ();
}詳細については、テストで使用されているDAOを確認してください。
「jsonb_extract_path_text」は、「text []」(#>>オペレーターに相当)として渡されたパス要素が指し示したテキストとしてJSON値を返すpostgreSql関数です。詳細については、PostgreSQLドキュメントを確認してください。以下には、「いいね」オペレーターと一致する特定の文字列値を含むアイテムを探す方法のHibernate 5の例があります。
public List < Item > findAllByStringValueAndLikeOperator ( String expression ) {
CriteriaBuilder cb = entityManager . getCriteriaBuilder ();
CriteriaQuery < Item > query = cb . createQuery ( Item . class );
Root < Item > root = query . from ( Item . class );
query . select ( root );
query . where ( cb . like ( new JsonBExtractPathText (( CriteriaBuilderImpl ) cb , singletonList ( "string_value" ), root . get ( "jsonbContent" )), expression ));
return entityManager . createQuery ( query ). getResultList ();
}上記の方法では、HibernateがHQLクエリを実行します。
select
generatedAlias0
from
Item as generatedAlias0
where
jsonb_extract_path_text( generatedAlias0 . jsonbContent , :param0 ) like :param1ネイティブSQLは以下のフォームを使用する予定です。
select
item0_ . id as id1_0_,
item0_ . jsonb_content as jsonb_co2_0_
from
item item0_
where
jsonb_extract_path_text( item0_ . jsonb_content ,?) like ?in operatorの詳細と例については、数値値の使用方法については、テストで使用されているDAOを確認してください。
Hibernate 6例:
以下には、上記と同じ例がありますが、冬眠6の場合。
....
public List < Item > findAllByStringValueAndLikeOperator ( String expression ) {
CriteriaBuilder cb = entityManager . getCriteriaBuilder ();
CriteriaQuery < Item > query = cb . createQuery ( Item . class );
Root < Item > root = query . from ( Item . class );
query . select ( root );
query . where ( cb . like ( new JsonBExtractPathText ( root . get ( "jsonbContent" ), singletonList ( "string_value" ), ( NodeBuilder ) cb ), expression ));
return entityManager . createQuery ( query ). getResultList ();
}詳細については、テストで使用されているDAOを確認してください。
JSonballArrayStringSexistPredicateタイプは、JSONアレイプロパティに渡された文字列配列が存在するかどうかをチェックする述語を表します。この述語の最初の例は、「jsonbextractpath -jsonb_extract_path」セクションで導入されました。これらの述語は、「DDLの変更を適用する」セクションで言及されているデフォルト名JSONB_ALL_ARRAY_STRINGS_EXISTを持つSQL関数が存在すると仮定しています。オペレーターとの組み合わせの以下の例は、すべての検索文字列がないアイテムを提示しません。 Hibernate 5のみで有効な例!
public List < Item > findAllThatDoNotMatchByAllMatchingTags ( Set < String > tags ) {
CriteriaBuilder cb = entityManager . getCriteriaBuilder ();
CriteriaQuery < Item > query = cb . createQuery ( Item . class );
Root < Item > root = query . from ( Item . class );
query . select ( root );
Predicate notAllMatchingTags = cb . not ( new JsonbAllArrayStringsExistPredicate ( hibernateContext , ( CriteriaBuilderImpl ) cb , new JsonBExtractPath (( CriteriaBuilderImpl ) cb , singletonList ( "top_element_with_set_of_values" ), root . get ( "jsonbContent" )), tags . toArray ( new String [ 0 ])));
Predicate withoutSetOfValuesProperty = cb . isNull ( new JsonBExtractPath (( CriteriaBuilderImpl ) cb , singletonList ( "top_element_with_set_of_values" ), root . get ( "jsonbContent" )));
query . where ( cb . or ( withoutSetOfValuesProperty , notAllMatchingTags ));
return entityManager . createQuery ( query ). getResultList ();
}上記の方法では、HibernateがHQLクエリを実行します。
select
generatedAlias0
from
Item as generatedAlias0
where
(
jsonb_extract_path( generatedAlias0 . jsonbContent , :param0 ) is null
)
or (
jsonb_all_array_strings_exist( jsonb_extract_path( generatedAlias0 . jsonbContent , :param1 ) , json_function_json_array(:param2, :param3)) = FALSE
)ネイティブSQLは以下のフォームを使用する予定です。
select
item0_ . id as id1_0_,
item0_ . jsonb_content as jsonb_co2_0_
from
item item0_
where
jsonb_extract_path( item0_ . jsonb_content ,?) is null
or jsonb_all_array_strings_exist(jsonb_extract_path( item0_ . jsonb_content ,?), array[?,?]) = falseHibernate 6例:
以下には、上記と同じ例がありますが、冬眠6の場合。
public List < Item > findAllThatDoNotMatchByAllMatchingTags ( Set < String > tags ) {
CriteriaBuilder cb = entityManager . getCriteriaBuilder ();
CriteriaQuery < Item > query = cb . createQuery ( Item . class );
Root < Item > root = query . from ( Item . class );
query . select ( root );
Predicate notAllMatchingTags = cb . not ( new JsonbAllArrayStringsExistPredicate ( hibernateContext , ( NodeBuilder ) cb , new JsonBExtractPath ( root . get ( "jsonbContent" ), ( NodeBuilder ) cb , singletonList ( "top_element_with_set_of_values" )), tags . toArray ( new String [ 0 ])));
Predicate withoutSetOfValuesProperty = cb . isNull ( new JsonBExtractPath ( root . get ( "jsonbContent" ), ( NodeBuilder ) cb , singletonList ( "top_element_with_set_of_values" )));
query . where ( cb . or ( withoutSetOfValuesProperty , notAllMatchingTags ));
return entityManager . createQuery ( query ). getResultList ();
}詳細については、テストで使用されているDAOを確認してください。
JSonBanyArrayStringSexistPredicateタイプは、JSONアレイプロパティに渡された文字列配列が存在するかどうかをチェックする述語を表します。これらの述語では、「DDLの変更を適用する」セクションで言及されているデフォルト名JSONB_ANY_ARRAY_STRINGS_EXISTを持つSQL関数が存在すると想定しています。以下には、配列を保持するプロパティが含まれているすべてのアイテムを探す方法の例があります。 Hibernate 5のみで有効な例!
public List < Item > findAllByAnyMatchingTags ( HashSet < String > tags ) {
CriteriaBuilder cb = entityManager . getCriteriaBuilder ();
CriteriaQuery < Item > query = cb . createQuery ( Item . class );
Root < Item > root = query . from ( Item . class );
query . select ( root );
query . where ( new JsonbAnyArrayStringsExistPredicate ( hibernateContext , ( CriteriaBuilderImpl ) cb , new JsonBExtractPath (( CriteriaBuilderImpl ) cb , singletonList ( "top_element_with_set_of_values" ), root . get ( "jsonbContent" )), tags . toArray ( new String [ 0 ])));
return entityManager . createQuery ( query ). getResultList ();
}上記の方法では、HibernateがHQLクエリを実行します。
select
generatedAlias0
from
Item as generatedAlias0
where
jsonb_any_array_strings_exist( jsonb_extract_path( generatedAlias0 . jsonbContent , :param0 ) , json_function_json_array(:param1, :param2)) = TRUEネイティブSQLは以下のフォームを使用する予定です。
select
item0_ . id as id1_0_,
item0_ . jsonb_content as jsonb_co2_0_
from
item item0_
where
jsonb_any_array_strings_exist(jsonb_extract_path( item0_ . jsonb_content ,?), array[?,?]) = trueHibernate 6例:
以下には、上記と同じ例がありますが、冬眠6の場合。
public List < Item > findAllByAnyMatchingTags ( HashSet < String > tags ) {
CriteriaBuilder cb = entityManager . getCriteriaBuilder ();
CriteriaQuery < Item > query = cb . createQuery ( Item . class );
Root < Item > root = query . from ( Item . class );
query . select ( root );
query . where ( new JsonbAnyArrayStringsExistPredicate ( hibernateContext , ( NodeBuilder ) cb , new JsonBExtractPath ( root . get ( "jsonbContent" ), ( NodeBuilder ) cb , singletonList ( "top_element_with_set_of_values" )), tags . toArray ( new String [ 0 ])));
return entityManager . createQuery ( query ). getResultList ();
}in operatorの詳細と例については、数値値の使用方法については、テストで使用されているDAOを確認してください。
ライブラリは、JSON修正操作にも使用できます。デフォルトでは、Hibernateでは、値全体を設定することにより、JSONコンテンツを使用していつでも列を更新できます。 Posjsonhelperライブラリを使用すると、完全なコンテンツを交換せずに個々のJSONプロパティを設定、交換、または削除することにより、JSONコンテンツを変更することもできます。ライブラリには、このタイプの操作を可能にするいくつかのJSON関数と演算子が含まれています。
jsonb_set関数のラッパー。この関数は、JSONパスに基づいてJSONプロパティの値を設定または置き換えます。 CriteriaUpDateコンポーネントで使用する方法の次の例をご覧ください。
// GIVEN
Long itemId = 19L ;
String property = "birthday" ;
String value = "1970-01-01" ;
String expectedJson = "{ " child " : { " pets " : [ " dog " ], " birthday " : " 1970-01-01 " }}" ;
// when
CriteriaUpdate < Item > criteriaUpdate = entityManager . getCriteriaBuilder (). createCriteriaUpdate ( Item . class );
Root < Item > root = criteriaUpdate . from ( Item . class );
// Set the property you want to update and the new value
criteriaUpdate . set ( "jsonbContent" , new JsonbSetFunction (( NodeBuilder ) entityManager . getCriteriaBuilder (), root . get ( "jsonbContent" ), new JsonTextArrayBuilder (). append ( "child" ). append ( property ). build (). toString (), JSONObject . quote ( value ), hibernateContext ));
// Add any conditions to restrict which entities will be updated
criteriaUpdate . where ( entityManager . getCriteriaBuilder (). equal ( root . get ( "id" ), itemId ));
// Execute the update
entityManager . createQuery ( criteriaUpdate ). executeUpdate ();
// then
Item item = tested . findById ( itemId );
assertThat (( String ) JsonPath . read ( item . getJsonbContent (), "$.child." + property )). isEqualTo ( value );
JSONObject jsonObject = new JSONObject ( expectedJson );
DocumentContext document = JsonPath . parse (( Object ) JsonPath . read ( item . getJsonbContent (), "$" ));
assertThat ( document . jsonString ()). isEqualTo ( jsonObject . toString ());これにより、次のSQLアップデートステートメントが生成されます。
update
item
set
jsonb_content = jsonb_set(jsonb_content, ?:: text [], ?::jsonb)
where
id = ?
Hibernate:
select
i1_0 . id ,
i1_0 . jsonb_content
from
item i1_0
where
i1_0 . id = ?この機能は、次の例のように、HQLステートメントでも使用できます。
@ Transactional
public void updateJsonBySettingPropertyForItemByHQL ( Long itemId , String property , String value ) {
// Execute the update
String hqlUpdate = "UPDATE Item SET jsonbContent = jsonb_set(jsonbContent, %s(:path, 'text[]'), %s(:json, 'jsonb' ) ) WHERE id = :id" . formatted ( hibernateContext . getCastFunctionOperator (), hibernateContext . getCastFunctionOperator ());
int updatedEntities = entityManager . createQuery ( hqlUpdate )
. setParameter ( "id" , itemId )
. setParameter ( "path" , new JsonTextArrayBuilder (). append ( "child" ). append ( property ). build (). toString ())
. setParameter ( "json" , JSONObject . quote ( value ))
. executeUpdate ();
}連結演算子のラッパー。ラッパーは、2つのJSONB値を新しいJSONB値に連結します。 CriteriaUpDateコンポーネントで使用する方法の次の例をご覧ください。
// GIVEN
Long itemId = 19l ;
String property = "birthday" ;
String value = "1970-01-01" ;
// WHEN
CriteriaUpdate < Item > criteriaUpdate = entityManager . getCriteriaBuilder (). createCriteriaUpdate ( Item . class );
Root < Item > root = criteriaUpdate . from ( Item . class );
JSONObject jsonObject = new JSONObject ();
jsonObject . put ( "child" , new JSONObject ());
jsonObject . getJSONObject ( "child" ). put ( property , value );
criteriaUpdate . set ( "jsonbContent" , new ConcatenateJsonbOperator (( NodeBuilder ) entityManager . getCriteriaBuilder (), root . get ( "jsonbContent" ), jsonObject . toString (), hibernateContext ));
criteriaUpdate . where ( entityManager . getCriteriaBuilder (). equal ( root . get ( "id" ), itemId ));
entityManager . createQuery ( criteriaUpdate ). executeUpdate ();
// THEN
Item item = tested . findById ( itemId );
assertThat (( String ) JsonPath . read ( item . getJsonbContent (), "$.child." + property )). isEqualTo ( value );
JSONObject expectedJsonObject = new JSONObject (). put ( property , value );
DocumentContext document = JsonPath . parse (( Object ) JsonPath . read ( item . getJsonbContent (), "$.child" ));
assertThat ( document . jsonString ()). isEqualTo ( expectedJsonObject . toString ());これにより、次のSQLアップデートステートメントが生成されます。
update
item
set
jsonb_content = jsonb_content || ?::jsonb
where
id = ?
Hibernate:
select
i1_0 . id ,
i1_0 . jsonb_content
from
item i1_0
where
i1_0 . id = ?この機能は、次の例のように、HQLステートメントでも使用できます。
@ Transactional
public void updateJsonPropertyForItemByHQL ( Long itemId , String property , String value ) throws JSONException {
JSONObject jsonObject = new JSONObject ();
jsonObject . put ( "child" , new JSONObject ());
jsonObject . getJSONObject ( "child" ). put ( property , value );
String hqlUpdate = "UPDATE Item SET jsonbContent = %s(jsonbContent, %s(:json, 'jsonb' ) ) WHERE id = :id" . formatted ( hibernateContext . getConcatenateJsonbOperator (), hibernateContext . getCastFunctionOperator ());
int updatedEntities = entityManager . createQuery ( hqlUpdate )
. setParameter ( "id" , itemId )
. setParameter ( "json" , jsonObject . toString ())
. executeUpdate ();
}削除演算子のラッパー '# - '。ラッパーは、パス要素がフィールドキーまたはアレイインデックスのいずれかにすることができる指定されたパスのインデックスに基づいて、フィールドまたは配列要素を削除します。 CriteriaUpDateコンポーネントで使用する方法の次の例をご覧ください。
// GIVEN
Item item = tested . findById ( 19L );
JSONObject jsonObject = new JSONObject ( "{ " child " : { " pets " : [ " dog " ]}}" );
DocumentContext document = JsonPath . parse (( Object ) JsonPath . read ( item . getJsonbContent (), "$" ));
assertThat ( document . jsonString ()). isEqualTo ( jsonObject . toString ());
// WHEN
CriteriaUpdate < Item > criteriaUpdate = entityManager . getCriteriaBuilder (). createCriteriaUpdate ( Item . class );
Root < Item > root = criteriaUpdate . from ( Item . class );
// Set the property you want to update and the new value
criteriaUpdate . set ( "jsonbContent" , new DeleteJsonbBySpecifiedPathOperator (( NodeBuilder ) entityManager . getCriteriaBuilder (), root . get ( "jsonbContent" ), new JsonTextArrayBuilder (). append ( "child" ). append ( "pets" ). build (). toString (), hibernateContext ));
// Add any conditions to restrict which entities will be updated
criteriaUpdate . where ( entityManager . getCriteriaBuilder (). equal ( root . get ( "id" ), 19L ));
// Execute the update
entityManager . createQuery ( criteriaUpdate ). executeUpdate ();
// THEN
entityManager . refresh ( item );
jsonObject = new JSONObject ( "{ " child " : {}}" );
document = JsonPath . parse (( Object ) JsonPath . read ( item . getJsonbContent (), "$" ));
assertThat ( document . jsonString ()). isEqualTo ( jsonObject . toString ());これにより、次のSQLアップデートステートメントが生成されます。
update
item
set
jsonb_content = (jsonb_content # - ?::text[])
where
id = ?この機能は、次の例のように、HQLステートメントでも使用できます。
@ Transactional
public void updateJsonByDeletingSpecificPropertyForItemByHql ( Long itemId , String property ) {
// Execute the update
String hqlUpdate = "UPDATE Item SET jsonbContent = %s(jsonbContent, %s(:path, 'text[]') ) WHERE id = :id" . formatted ( hibernateContext . getDeleteJsonBySpecificPathOperator (), hibernateContext . getCastFunctionOperator ());
int updatedEntities = entityManager . createQuery ( hqlUpdate )
. setParameter ( "id" , itemId )
. setParameter ( "path" , new JsonTextArrayBuilder (). append ( "child" ). append ( property ). build (). toString ())
. executeUpdate ();
}RemoveJSonValuesfromJsonArrayFunctionタイプは、Posjsonhelperライブラリによって生成されたSQL関数を呼び出す冬眠オペレーターです。デフォルトでは、生成された関数は以下の例のように見えます。
CREATE OR REPLACE FUNCTION {{schema}}.remove_values_from_json_array(input_json jsonb, values_to_remove jsonb) RETURNS jsonb AS $$
DECLARE
result jsonb;
BEGIN
IF jsonb_typeof(values_to_remove) <> ' array ' THEN
RAISE EXCEPTION ' values_to_remove must be a JSON array ' ;
END IF;
result : = (
SELECT jsonb_agg(element)
FROM jsonb_array_elements(input_json) AS element
WHERE NOT (element IN ( SELECT jsonb_array_elements(values_to_remove)))
);
RETURN COALESCE(result, ' [] ' ::jsonb);
END;
$$ LANGUAGE plpgsql;関数には2つの入力パラメーターがあります。最初はJSONアレイです。これは、関数が返される結果のベース配列です。 2番目のパラメーターは、結果配列から削除する要素を表すJSONアレイでもあります。以下は、SQLアップデートステートメントでJSON列を更新するためにこの機能を別の演算子で使用する方法のコード例です。
// GIVEN
Item item = tested . findById ( 24L );
DocumentContext document = JsonPath . parse (( Object ) JsonPath . read ( item . getJsonbContent (), "$" ));
assertThat ( document . jsonString ()). isEqualTo ( "{ " child " :{ " pets " :[ " crab " , " chameleon " ]}, " inventory " :[ " mask " , " fins " , " compass " ]}" );
CriteriaUpdate < Item > criteriaUpdate = entityManager . getCriteriaBuilder (). createCriteriaUpdate ( Item . class );
Root < Item > root = criteriaUpdate . from ( Item . class );
NodeBuilder nodeBuilder = ( NodeBuilder ) entityManager . getCriteriaBuilder ();
JSONArray toRemoveJSONArray = new JSONArray ( Arrays . asList ( "mask" , "compass" ));
RemoveJsonValuesFromJsonArrayFunction deleteOperator = new RemoveJsonValuesFromJsonArrayFunction ( nodeBuilder , new JsonBExtractPath ( root . get ( "jsonbContent" ), nodeBuilder , Arrays . asList ( "inventory" )), toRemoveJSONArray . toString (), hibernateContext );
JsonbSetFunction jsonbSetFunction = new JsonbSetFunction ( nodeBuilder , ( SqmTypedNode ) root . get ( "jsonbContent" ), new JsonTextArrayBuilder (). append ( "inventory" ). build (). toString (), deleteOperator , hibernateContext );
// Set the property you want to update and the new value
criteriaUpdate . set ( "jsonbContent" , jsonbSetFunction );
// Add any conditions to restrict which entities will be updated
criteriaUpdate . where ( entityManager . getCriteriaBuilder (). equal ( root . get ( "id" ), 24L ));
// WHEN
entityManager . createQuery ( criteriaUpdate ). executeUpdate ();
// THEN
entityManager . refresh ( item );
document = JsonPath . parse (( Object ) JsonPath . read ( item . getJsonbContent (), "$" ));
assertThat ( document . jsonString ()). isEqualTo ( "{ " child " :{ " pets " :[ " crab " , " chameleon " ]}, " inventory " :[ " fins " ]}" );同じ例ですが、HQLクエリの例:
// GIVEN
Item item = tested . findById ( 24L );
DocumentContext document = JsonPath . parse (( Object ) JsonPath . read ( item . getJsonbContent (), "$" ));
assertThat ( document . jsonString ()). isEqualTo ( "{ " child " :{ " pets " :[ " crab " , " chameleon " ]}, " inventory " :[ " mask " , " fins " , " compass " ]}" );
CriteriaUpdate < Item > criteriaUpdate = entityManager . getCriteriaBuilder (). createCriteriaUpdate ( Item . class );
Root < Item > root = criteriaUpdate . from ( Item . class );
JSONArray toRemoveJSONArray = new JSONArray ( Arrays . asList ( "mask" , "compass" ));
String hqlUpdate = "UPDATE Item SET jsonbContent = %s(jsonbContent, %s(:path, 'text[]'), %s(jsonb_extract_path( jsonbContent , 'inventory' ), %s(:to_remove, 'jsonb')) ) WHERE id = :id" . formatted ( JSONB_SET_FUNCTION_NAME , hibernateContext . getCastFunctionOperator (), hibernateContext . getRemoveJsonValuesFromJsonArrayFunction (), hibernateContext . getCastFunctionOperator ());
// WHEN
entityManager . createQuery ( hqlUpdate )
. setParameter ( "id" , 24L )
. setParameter ( "path" , new JsonTextArrayBuilder (). append ( "inventory" ). build (). toString ())
. setParameter ( "to_remove" , toRemoveJSONArray . toString ())
. executeUpdate ();
// THEN
entityManager . refresh ( item );
document = JsonPath . parse (( Object ) JsonPath . read ( item . getJsonbContent (), "$" ));
assertThat ( document . jsonString ()). isEqualTo ( "{ " child " :{ " pets " :[ " crab " , " chameleon " ]}, " inventory " :[ " fins " ]}" );これらの2つの例は、SQLステートメント以下を生成します。
update
item
set
jsonb_content = jsonb_set(jsonb_content, ?:: text [], remove_values_from_json_array(jsonb_extract_path(jsonb_content, ?), ?::jsonb))
where
id = ?単一のJSONB_SET関数を使用して、単一の更新ステートメントを使用してJSONの単一のプロパティを設定することは有用ですが、単一の更新ステートメントでJSONツリーの異なるレベルで複数のプロパティを設定できる方が便利かもしれません。
以下のコードの例を確認しないでください例:
// GIVEN
Item item = tested . findById ( 23L );
DocumentContext document = JsonPath . parse (( Object ) JsonPath . read ( item . getJsonbContent (), "$" ));
assertThat ( document . jsonString ()). isEqualTo ( "{ " child " :{ " pets " :[ " dog " ]}, " inventory " :[ " mask " , " fins " ], " nicknames " :{ " school " : " bambo " , " childhood " : " bob " }}" );
CriteriaUpdate < Item > criteriaUpdate = entityManager . getCriteriaBuilder (). createCriteriaUpdate ( Item . class );
Root < Item > root = criteriaUpdate . from ( Item . class );
Hibernate6JsonUpdateStatementBuilder hibernate6JsonUpdateStatementBuilder = new Hibernate6JsonUpdateStatementBuilder ( root . get ( "jsonbContent" ), ( NodeBuilder ) entityManager . getCriteriaBuilder (), hibernateContext );
hibernate6JsonUpdateStatementBuilder . appendJsonbSet ( new JsonTextArrayBuilder (). append ( "child" ). append ( "birthday" ). build (), quote ( "2021-11-23" ));
hibernate6JsonUpdateStatementBuilder . appendJsonbSet ( new JsonTextArrayBuilder (). append ( "child" ). append ( "pets" ). build (), "[ " cat " ]" );
hibernate6JsonUpdateStatementBuilder . appendDeleteBySpecificPath ( new JsonTextArrayBuilder (). append ( "inventory" ). append ( "0" ). build ());
hibernate6JsonUpdateStatementBuilder . appendJsonbSet ( new JsonTextArrayBuilder (). append ( "parents" ). append ( 0 ). build (), "{ " type " : " mom " , " name " : " simone " }" );
hibernate6JsonUpdateStatementBuilder . appendJsonbSet ( new JsonTextArrayBuilder (). append ( "parents" ). build (), "[]" );
hibernate6JsonUpdateStatementBuilder . appendDeleteBySpecificPath ( new JsonTextArrayBuilder (). append ( "nicknames" ). append ( "childhood" ). build ());
// Set the property you want to update and the new value
criteriaUpdate . set ( "jsonbContent" , hibernate6JsonUpdateStatementBuilder . build ());
// Add any conditions to restrict which entities will be updated
criteriaUpdate . where ( entityManager . getCriteriaBuilder (). equal ( root . get ( "id" ), 23L ));
// WHEN
entityManager . createQuery ( criteriaUpdate ). executeUpdate ();
// THEN
entityManager . refresh ( item );
document = JsonPath . parse (( Object ) JsonPath . read ( item . getJsonbContent (), "$" ));
assertThat ( document . jsonString ()). isEqualTo ( "{ " child " :{ " pets " :[ " cat " ], " birthday " : " 2021-11-23 " }, " parents " :[{ " name " : " simone " , " type " : " mom " }], " inventory " :[ " fins " ], " nicknames " :{ " school " : " bambo " }}" );上記のコードでは、3つのJSONプロパティ「child.birthday」、「child.pets」、「parents」を設定し、他の2つの「inventory.0」と「nicknames.childhood」を削除します。 「親」プロパティは、配列になると思われる新しいプロパティです。いくつかの値を備えた新しい配列プロパティを単一の操作で行うことはできますが、デモンストレーションの目的では2つの操作を使用します。 1つは、空のJSONアレイを値として「親」と呼ばれる新しいプロパティを設定するためです。特定のインデックスで配列の要素を設定する別の操作。より高いプロパティが存在しない場合、内部プロパティの前に作成する必要があります。幸いなことに、hibernate6jsonupdateStatementBuilderタイプのデフォルトインスタンスには、適切な操作順序を設定するのに役立つ適切なソートおよびフィルタリングコンポーネントがあります。したがって、Create-Array操作を追加する前または後にアドレイエレメント操作を追加するかどうかは関係ありません。デフォルトでは、コンテンツを削除する操作は、コンテンツを追加または交換する操作の前に追加されます。もちろん、これらのコンポーネントをnullに設定することにより、この動作を無効にすることができます。詳細については、hibernate6jsonupdatestatementBuilderタイプについてはJavadocを確認してください。
このコードは、SQLステートメント以下を生成します。
update
item
set
jsonb_content =
jsonb_set(
jsonb_set(
jsonb_set(
jsonb_set(
(
(jsonb_content # - ?::text[]) -- the most nested #- operator
# - ?::text[])
, ?:: text [], ?::jsonb) -- the most nested jsonb_set operation
, ?:: text [], ?::jsonb)
, ?:: text [], ?::jsonb)
, ?:: text [], ?::jsonb)
where
id = ?この準備されたステートメントの最も内部のJSONB_SET関数の実行は、「親」プロパティの空の配列を設定することになります。
ビルダーには、値を設定する方法があります。
プロパティの削除:
appendeletebyspecificpath(jsontextarray jsontextarray)
配列要素の追加
配列要素の削除
jsonアレイの変更に関連するいくつかの方法は、デフォルトではorg.json.jsonライブラリが必要です(オプションの依存関係を確認)。ただし、コレクションオブジェクトをJSONアレイ値にマップするインターフェイスのカスタム実装を「withcollectiontojsonarraystringmapper(com.github.starnowski.posjsonhelper.hibernate6.hibernate6jsonupdateStatementementementementementementementementementementementtatementtojsonarraystringmapper)」
hibernate6jsonupdateStatementBuilderタイプは一般的です。 2番目の汎用タイプは、hibernate6jsonupdateStatementementBuilderコンテキストに追加できるカスタム値です。以下は、タイプがアレイ操作を表すコード例です(アレイに追加および削除する要素)。
カスタム値タイプ:
private static class JsonArrayOperations {
private final List < String > toDelete ;
private final List < String > toAdd ;
public JsonArrayOperations ( List < String > toDelete , List < String > toAdd ) {
this . toDelete = toDelete ;
this . toAdd = toAdd ;
}
public List < String > getToDelete () {
return toDelete ;
}
public List < String > getToAdd () {
return toAdd ;
}
}使用例:
// GIVEN
Item item = tested . findById ( 24L );
DocumentContext document = JsonPath . parse (( Object ) JsonPath . read ( item . getJsonbContent (), "$" ));
assertThat ( document . jsonString ()). isEqualTo ( "{ " child " :{ " pets " :[ " crab " , " chameleon " ]}, " inventory " :[ " mask " , " fins " , " compass " ]}" );
CriteriaUpdate < Item > criteriaUpdate = entityManager . getCriteriaBuilder (). createCriteriaUpdate ( Item . class );
Root < Item > root = criteriaUpdate . from ( Item . class );
Hibernate6JsonUpdateStatementBuilder < Object , JsonArrayOperations > hibernate6JsonUpdateStatementBuilder = new Hibernate6JsonUpdateStatementBuilder ( root . get ( "jsonbContent" ), ( NodeBuilder ) entityManager . getCriteriaBuilder (), hibernateContext );
hibernate6JsonUpdateStatementBuilder . appendJsonbSet ( new JsonTextArrayBuilder (). append ( "child" ). append ( "pets" ). build (), null , new JsonArrayOperations ( Arrays . asList ( "crab" , "ant" ), Arrays . asList ( "lion" , "dolphin" )));
hibernate6JsonUpdateStatementBuilder . appendJsonbSet ( new JsonTextArrayBuilder (). append ( "name" ). build (), JSONObject . quote ( "Simon" ));
hibernate6JsonUpdateStatementBuilder . appendJsonbSet ( new JsonTextArrayBuilder (). append ( "inventory" ). build (), null , new JsonArrayOperations ( Arrays . asList ( "compass" , "mask" ), Arrays . asList ( "knife" )));
hibernate6JsonUpdateStatementBuilder . withJsonbSetFunctionFactory ( new Hibernate6JsonUpdateStatementBuilder . DefaultJsonbSetFunctionFactory < Object , JsonArrayOperations >() {
public JsonbSetFunction build ( NodeBuilder nodeBuilder , Path < Object > rootPath , JsonUpdateStatementConfiguration . JsonUpdateStatementOperation < JsonArrayOperations > operation , HibernateContext hibernateContext ) {
if ( operation . getCustomValue () != null ) {
JSONArray toAddJSONArray = new JSONArray ( operation . getCustomValue (). getToAdd ());
ConcatenateJsonbOperator concatenateOperator = new ConcatenateJsonbOperator ( nodeBuilder , new JsonBExtractPath ( rootPath , nodeBuilder , operation . getJsonTextArray (). getPath (). stream (). map ( ob -> ob . toString ()). collect ( Collectors . toList ())), toAddJSONArray . toString (), hibernateContext );
JSONArray toRemoveJSONArray = new JSONArray ( operation . getCustomValue (). getToDelete ());
RemoveJsonValuesFromJsonArrayFunction deleteOperator = new RemoveJsonValuesFromJsonArrayFunction ( nodeBuilder , concatenateOperator , toRemoveJSONArray . toString (), hibernateContext );
return new JsonbSetFunction ( nodeBuilder , ( SqmTypedNode ) rootPath , operation . getJsonTextArray (). toString (), deleteOperator , hibernateContext );
} else {
return super . build ( nodeBuilder , rootPath , operation , hibernateContext );
}
}
@ Override
public JsonbSetFunction build ( NodeBuilder nodeBuilder , SqmTypedNode sqmTypedNode , JsonUpdateStatementConfiguration . JsonUpdateStatementOperation < JsonArrayOperations > operation , HibernateContext hibernateContext ) {
if ( operation . getCustomValue () != null ) {
JSONArray toAddJSONArray = new JSONArray ( operation . getCustomValue (). getToAdd ());
ConcatenateJsonbOperator concatenateOperator = new ConcatenateJsonbOperator ( nodeBuilder , new JsonBExtractPath ( root . get ( "jsonbContent" ), nodeBuilder , operation . getJsonTextArray (). getPath (). stream (). map ( ob -> ob . toString ()). collect ( Collectors . toList ())), toAddJSONArray . toString (), hibernateContext );
JSONArray toRemoveJSONArray = new JSONArray ( operation . getCustomValue (). getToDelete ());
RemoveJsonValuesFromJsonArrayFunction deleteOperator = new RemoveJsonValuesFromJsonArrayFunction ( nodeBuilder , concatenateOperator , toRemoveJSONArray . toString (), hibernateContext );
return new JsonbSetFunction ( nodeBuilder , sqmTypedNode , operation . getJsonTextArray (). toString (), deleteOperator , hibernateContext );
} else {
return super . build ( nodeBuilder , sqmTypedNode , operation , hibernateContext );
}
}
});
// Set the property you want to update and the new value
criteriaUpdate . set ( "jsonbContent" , hibernate6JsonUpdateStatementBuilder . build ());
// Add any conditions to restrict which entities will be updated
criteriaUpdate . where ( entityManager . getCriteriaBuilder (). equal ( root . get ( "id" ), 24L ));
// WHEN
entityManager . createQuery ( criteriaUpdate ). executeUpdate ();
// THEN
entityManager . refresh ( item );
document = JsonPath . parse (( Object ) JsonPath . read ( item . getJsonbContent (), "$" ));
assertThat ( document . jsonString ()). isEqualTo ( "{ " name " : " Simon " , " child " :{ " pets " :[ " chameleon " , " lion " , " dolphin " ]}, " inventory " :[ " fins " , " knife " ]}" );| プロパティ名 | 説明 |
|---|---|
| com.github.starnowski.posjsonhelper.core.functions.jsonb_all_array_strings_exist | すべての要素がテキスト[]がJSONアレイプロパティに存在するかどうかをチェックするSQL関数の名前。デフォルトでは、名前はjsonb_all_array_strings_existです |
| com.github.starnowski.posjsonhelper.core.functions.jsonb_any_array_strings_exist | JSONアレイプロパティにテキスト[]が存在するように渡された要素があるかどうかをチェックするSQL関数の名前。デフォルトでは、名前はjsonb_any_array_strings_existです |
| com.github.starnowski.posjsonhelper.core.functions.remove_values_from_json_array | JSONBアレイから要素を削除してJSONBアレイを返すSQL関数の名前は、関数の入力として渡されました。デフォルトでは、名前はremove_values_from_json_arrayです |
| com.github.starnowski.posjsonhelper.core.schema | SQL機能を作成するデータベーススキーマの名前 |
| com.github.starnowski.posjsonhelper.core.hibernate.functions.jsonb_all_array_strings_exist | com.github.starnowski.posjsonhelper.core.core.functions.jsonb_all_array_strings_existプロパティによって指定されたSQL関数を呼び出すHQL関数の名前。デフォルトでは、名前はjsonb_all_array_strings_existです |
| com.github.starnowski.posjsonhelper.core.hibernate.functions.jsonb_any_array_strings_exist | com.github.starnowski.posjsonhelper.core.functions.jsonb_any_array_strings_existプロパティによって指定されたSQL関数を呼び出すHQL関数の名前。デフォルトでは、名前はjsonb_any_array_strings_existです |
| com.github.starnowski.posjsonhelper.core.hibernate.functions.json_function_json_array | Array演算子をPostgreSQLにラップするHQL関数の名前。デフォルトでは、名前はjson_function_json_arrayです |
| com.github.starnowski.posjsonhelper.core.hibernate.functions.remove_values_from_json_array | JSONBアレイの要素を削除してJSONBアレイを返す関数をラップするHQL関数の名前は、関数の入力として渡されます。デフォルトでは、名前はremove_values_from_json_arrayです |
| com.github.starnowski.posjsonhelper.core.hibernate.functions.sqldefinitionContextFactory.types | com.github.starnowski.posjsonhelper.core.sql.isqldefinitionContextFactoryタイプのリストのリストを保存するシステムプロパティ。 「com.github.starnowski.posjsonhelper」のパッケージのクラスパスにあるタイプをロードする代わりに。リストのタイプは、コンマ文字 "。"によって区切られています。 |
| com.github.starnowski.posjsonhelper.hibernate6.functiondescriptorregisterfactory.types | (hibernate 6でのみ使用)com.github.starnowski.posjsonhelper.hibernate6.descriptor.functiondescriptorregisterfactoriessupplierタイプのロードする必要があるシステムのリストを保存するシステムプロパティ。 「com.github.starnowski.posjsonhelper」のパッケージのクラスパスにあるタイプをロードする代わりに。リストのタイプは、コンマ文字 "。"によって区切られています。 |
| com.github.starnowski.posjsonhelper.hibernate6.functiondescriptorregisterfactory.types.excluded | (Hibernate 6でのみ使用)com.github.starnowski.posjsonhelper.hibernate6.descriptor.functiondescriptorregisterfactoriessupplierタイプのリストをcom.github.starnowski.posjsonhelper.hibernate6.descriptorを保存するシステムプロパティ。 "com.github.starnowski.posjsonhelper.hibernate6.functiondescriptorregisterfactory.types"プロパティも指定されている場合、com.github.starnowski.posjsonhelper.hibernate6.functiondescriptorregisterfactory.types "リストのタイプは、コンマ文字 "。"によって区切られています。 |
Hibernate 6の互換性マトリックス6。
| posjsonhelper | 冬眠6 |
|---|---|
| 0.3.0 | 6.4.0。ファイナル |
| 0.2.0-0.2.1 | 6.1.5.Final |
Hibernateパッケージ、バージョン、またはクラスなどの問題
失われたメソッドの定義に関連する問題に直面している場合、または次のようにタイプします。
java.lang.NoSuchMethodError: 'org.hibernate.query.criteria.JpaExpression
次に、プロジェクトがClassPathにHibernate-Coreライブラリがあるかどうかを確認してください。 Hibernate-Coreはこのプロジェクトのオプションの依存関係であり、プロジェクトに追加されたことを確認する必要があります。同様の問題145を確認してください。冬眠中のコアがClassPathにあり、問題がまだ存在している場合は、問題を報告してください。