2017-02-16 8 views
0

のいずれかの事実のためにnullを返します確かにそこにあるのですが、私がそれを取り戻そうとすると、factHandleのオブジェクトはnullです。私はIDベースのアサーションモードでDroolsを使用しようとしています。私の関連する質問は次のとおりです:getFactHandle方法は、私は次のコードを持っているDroolsの

  1. なぜ私のファクトはnullになりますか?メモリ内のsomeFactの位置がDo something else with someFact, insert it into some db段階で変更されている可能性があります。問題に影響しますか?
  2. DroolsはIDをどのように比較しますか?私は@Idと注釈されたsomeFactオブジェクトにprivate long idを提出しました。
  3. は、次のように私は私のKieContainerKieBaseを作成しています:私は平等に基づく表明に切り替える必要がある場合

`` `

@Bean 
public KieServices kieServices() { 
    return KieServices.Factory.get(); 
} 

@Bean 
public KieContainer kieContainer() throws IOException { 

    final KieRepository kieRepository = kieServices().getRepository(); 

    kieRepository.addKieModule(new KieModule() { 
     @Override 
     public ReleaseId getReleaseId() { 
      return kieRepository.getDefaultReleaseId(); 
     } 
    }); 

    KieFileSystem kfs = kieServices().newKieFileSystem(); 
    PathMatchingResourcePatternResolver pmrs = new PathMatchingResourcePatternResolver(); 
    Resource[] files = pmrs.getResources("classpath*:com/company/**/rules/*.drl"); 

    for(Resource file : files) { 
     String myString = IOUtils.toString(file.getInputStream(), "UTF-8"); 
     kfs.write("src/main/resources/"+ file.getFilename(), myString); 
    } 

    KieBuilder kieBuilder = kieServices().newKieBuilder(kfs); 
    kieBuilder.buildAll(); 
    return kieServices().newKieContainer(kieRepository.getDefaultReleaseId()); 
} 

@Bean 
public KieBase kieBase() throws IOException { 
    KieBaseConfiguration kieBaseConfiguration = kieServices().newKieBaseConfiguration(); 
    kieBaseConfiguration.setProperty("assertBehaviour", "equality"); 
    return KnowledgeBaseFactory.newKnowledgeBase(kieBaseConfiguration); 
} 

` ``

を、私が実装したequalsと私のオブジェクト上のhashCodeメソッドが見つかりましたKieBaseのアサーションをEQUALITYとして定義する方法を見つけることができませんでした。どうやってやるの?

答えて

0
  1. Droolsのアイデンティティモードを使用して比較することができないので、単にDo something else with someFact, insert it into some dbで変更されているメモリ内someFactの位置は、効果を有しています。
  2. メモリ内の場所。 Javax @Id注釈ではありません。
  3. 次はあなたが平等モードにエンジンを置く方法です:

    KieBaseConfiguration kieBaseConfiguration = kieServices().newKieBaseConfiguration(); 
        kieBaseConfiguration.setOption(EqualityBehaviorOption.EQUALITY); 
        return kieContainer().newKieBase(kieBaseConfiguration); 
    
関連する問題