Hi all, I am new to AXON IVY. Hope you can be patient with me.

I am trying to use that code here: https://answers.axonivy.com/questions/314/using-db-connection-from-pis (provided by Ivy Support Team) in a Java class in a CustomValidator class to look up a database table. Somehow I could not resolve the Ivy object.

I tried looking up getProcessEngineHook method in https://developer.axonivy.com/doc/latest/PublicAPI but the search doesn't return any results.

My codes as follows:

package trial.facesValidation;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
import  java.sql.Connection;

// To validate if Item Name already existed in Parts table in Database
@FacesValidator("trial.facesValidation.CustomItemValidator")
public class CustomItemValidator implements Validator {

    @Override
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException 
    {
        //connect to the database
        Connection dbconnection = ivy.getProcessEngineHook().getDbConnection("TrialDBConn");

        try
        {
        // execute some sql queries
        } finally {
        // close the connection
              dbconnection.close();
        }

asked 23.07 at 23:32

wesing's gravatar image

wesing
116
accept rate: 0%

converted to question 24.07 at 09:10

Reguel%20Wermelinger's gravatar image

Reguel Werme... ♦♦
7.1k11344


I think the code above is outdated since Axon.ivy 6.0.

But it should be possible to solve this problem by using JPA: https://developer.axonivy.com/doc/latest/DesignerGuideHtml/ivy.datamodeling.html#ivy-persistence-api

Then you could easily access the persistence unit or the EntityManager itself and query any objects out of the database. Similar as shown here: https://answers.axonivy.com/questions/1102/how-to-use-jpa-entity-manager-instead-of-ivy-entity-manager/1103

The rough steps to use JPA in an ivy project:

  1. define an external database as data store: https://developer.axonivy.com/doc/latest/DesignerGuideHtml/ivy.configuration.html#ivy-database
  2. map it to a persistence unit provider: https://developer.axonivy.com/doc/latest/DesignerGuideHtml/ivy.datamodeling.html#ivy-editors-persistence-configuration
  3. generate JPA pojos: https://developer.axonivy.com/doc/latest/DesignerGuideHtml/ivy.datamodeling.html#ivy-persistence-entityclasses
link

answered 24.07 at 09:14

Reguel%20Wermelinger's gravatar image

Reguel Werme... ♦♦
7.1k11344
accept rate: 70%

edited 24.07 at 09:19

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×73
×3

Asked: 23.07 at 23:32

Seen: 101 times

Last updated: 24.07 at 09:19