oasp / oasp4j

The Open Application Standard Platform for Java
Apache License 2.0
60 stars 303 forks source link

Changes in the OASP4J Framework to address the issue of providing Column Annotation for user attribute (mapped to column user in database) explicitly in AdvancedRevisionEntity for databases MSSQL Server, PostGres, Oracle #516

Closed kiran-vadla closed 7 years ago

kiran-vadla commented 7 years ago

Changes in the OASP4J Framework to address the issue of providing Column Annotation for user attribute (mapped to column user in database) explicitly in AdvancedRevisionEntity for databases MSSQL Server, PostGres, Oracle

kiran-vadla commented 7 years ago

@hohwille , Any thoughts on this ? As of now , the workaround provided for this DBIntegration Git hub issue is that one has to change AdvancedRevisionEntiy as per the instructions at https://github.com/oasp/oasp4j/wiki/guide-database-migration#database-integration and recompile oasp4j .

The instructions at the wiki say that, to integrate OASP4J with corresponding Database , User (a developer in this case) has to configure spring active profile, say for eg: orcl in case of Oracle Database in oasp4j/samples/src/main/resources/config/application.properties of sample project that is created.

After that , Column annotation for 'user' attribute in AdvancedRevisionEntity has to be changed manually. Hibernate generates the SQL for this Entity accordingly.

Challenges , I see here are

  1. making the spring active profile information available from the sample application that is created inside oasp4j/oasp4j-jpa-envers project (and in AdvancedRevisionEnity probably) so as to manipulate the Column annotation for 'user' attribute in AdvancedRevisionEntity on the fly using JavaAssist or any other ByteCode Engineering APIs . Even if this is possible , I don't think this is a concrete solution since the component (in this case oasp4j) that is provided is being manipulated runtime at the User end.

Appreciate your suggestions/thoughts.

Thanks, Kiran.

hohwille commented 7 years ago

To make things clear - we are talking about this class: https://github.com/oasp/oasp4j/blob/develop/modules/jpa-envers/src/main/java/io/oasp/module/jpa/dataaccess/api/AdvancedRevisionEntity.java

Your observation is that the column name user is causing problems in some databases because of keyword-conflicts, correct? When does that problem occur? Because I am using OASP in my project with Oracle Database and we did not have to change anything here to make it work. Without a detailed stracktrace I can not tell you if simply do something wrong or different that is causing the problem. What configuration are you using for hbm2ddl? Do you have the schema in flyway scripts? When does the error occur? If the workaround is to add a column annotation with the quoted column name, would that workaround cause problems in other databases? Coulnd't all this be solved via SQL Dialect?

My input for the aspects are:

kiran-vadla commented 7 years ago

@hohwille , thanks for the inputs . I will reproduce the problem/error and provide the full stacktrace.

Thanks, Kiran.

kiran-vadla commented 7 years ago

@hohwille , for Oracle 11g , there is no separate dialect , we have to use Oracle 10g dialect 'org.hibernate.dialect.Oracle10gDialect' . I am using the same.

Regarding 'hbm2ddl', I am not overriding it . It is the same that is defined at (https://github.com/oasp/oasp4j/blob/develop/modules/jpa/src/test/resources/config/app/application-default.properties) database.hibernate.hbm2ddl.auto = create.

Attached is the full stack trace of the error that I receive when I don't add the column annotation '@Column(name = "\"user\"")' for user attribute in https://github.com/oasp/oasp4j/blob/develop/modules/jpa- detailedError.txt envers/src/main/java/io/oasp/module/jpa/dataaccess/api/AdvancedRevisionEntity.java.

Pls let me know.

Thanks, Kiran.

kiran-vadla commented 7 years ago

Hi @hohwille ,

Just to keep you posted , I have tried overriding 'database.hibernate.hbm2ddl.auto' in sample project . Tried 'update' and 'validate' for 'database.hibernate.hbm2ddl.auto' but in vain. I receive the same error.

Thanks, Kiran.

kiran-vadla commented 7 years ago

The fix for this issue is addressed as part of the Pull Request #526 (https://github.com/oasp/oasp4j/pull/526/)

hohwille commented 7 years ago

So the actual error is:

Caused by: java.sql.SQLSyntaxErrorException: ORA-01747: invalid user.table.column, table.column, or column specification

And that is triggered from here

at io.oasp.module.jpa.dataaccess.base.AbstractGenericDao.findOne(AbstractGenericDao.java:132)

What comes from here:

at io.oasp.gastronomy.restaurant.salesmanagement.logic.impl.usecase.UcFindBillImpl.findBill(UcFindBillImpl.java:41)
hohwille commented 7 years ago

https://github.com/oasp/oasp4j/blob/master/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/logic/impl/usecase/UcFindBillImpl.java#L40

So findOne on a Bill is not working.

Strange as Bill does not even use any keywords in column names:

https://github.com/oasp/oasp4j/blob/master/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/dataaccess/api/BillEntity.java

Too bad that Oracle generates such lousy error messages and does not even tell us the exact table and column causing the problem.

hohwille commented 7 years ago

However the hbm2ddl property should be set to verify for real usage (application.properties located in default package). For development (config/application.properties) it may be overridden to create. But that may be part of the problem.

hohwille commented 7 years ago

I guess there is a simple solution to the problem but this might require some deeper research. As I said earlier a simple solution to the problem is just to rename the columns entirely to avoid the use of reserved keywords. However, this will cause a compatibility issue. You could also deprecate the related class and create a new copy of it and there simply rename the column(s) (e.g. login instead of user, etc.).

kiran-vadla commented 7 years ago

@hohwille , I have incorporated the changes related to deprecating AdvancedRevisionEntity and creating a new copy and renaming the column to 'userName' instead of 'user' . These changes are submitted as part of PR #526. Please review.

Thanks, Kiran.

kiran-vadla commented 7 years ago

Addressed as part of PR #526 .

Thanks, @kiran-vadla