I am generating objects using Mybatis generator. I was able to generate the classes with actual tablename in that schema. But gave select permission to different schema on that table and created a private synonym. I would like to generate objects using that synonym.

<table tableName="PrivateSynonym" domainObjectName="PrivateSynonym" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true" modelType="flat"> <property name="useActualColumnNames" value="true" /> </table> 

I tried with above example it did not work. It says there is no table mapped with PrivateSynonym. Is it possible to use synonym to generate objects? Any help on this is so much appreciated.

1 Answer

The ability to generate from synonyms is dependent on the JDBC driver, but I'm not surprised it isn't working. The generator uses the DatabaseMetaData.getColumns() method to learn about tables and it is not surprising that synonyms are ignored in the command by most drivers.

A solution for the issue is to generate code based on a table, but change the runtime names to something else. You could use a privileged ID to do the code generation, but use the synonyms in the generated code so users would not need the privileged ID. For example:

<table tableName="PrivateTable" schema="PrivateSchema"> <property name="runtimeTableName" value="PublicSynonym"/> <property name="runtimeSchema" value="PublicSchema"/> </table> 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy