Querydsl - sql : Rename a table

142 views
Skip to first unread message

Maths

unread,
Dec 8, 2019, 11:38:46 AM12/8/19
to Querydsl
Hi everyone,

I wanted to use querydsl-sql in version 4.2.1 to do some complicated queries.

I configured maven to export tables and it works.

But now, I wanted to use the option to rename table and it doesn't works for me :/
The extract of my pom.xml :

<plugin>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-maven-plugin</artifactId>
<version>${querydsl.version}</version>
<executions>
<execution>
<goals>
<goal>export</goal>
</goals>
</execution>
</executions>
<configuration>
<jdbcDriver>${pacifique.datasource.driver-class-name}</jdbcDriver>
<jdbcUrl>${pacifique.datasource.url}</jdbcUrl>
<jdbcUser>${pacifique.datasource.username}</jdbcUser>
<jdbcPassword>${pacifique.datasource.password}</jdbcPassword>
<packageName>fr.hm.pacifique.sql</packageName>
<targetFolder>${project.basedir}/target/generated-sources</targetFolder>
<sourceFolder>${project.basedir}/fr.hm.pacifique.domain</sourceFolder>
<tableNamePattern>sui_tr_log</tableNamePattern>
<exportInverseForeignKeys>false</exportInverseForeignKeys>
<innerClassesForKeys>true</innerClassesForKeys>
<renameMappings>
<renameMapping>
<fromTable>sui_tr_log</fromTable>
<toTable>message</toTable>
</renameMapping>
</renameMappings>
</configuration>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.8</version>
</dependency>
</dependencies>
</plugin>

Anyone already used this option ?
My configuration is bad ?

Thanks in advance,
Maths.

Luísa Pinto

unread,
Dec 9, 2019, 8:56:24 AM12/9/19
to Querydsl
Hi

A little bit more detail on your error would be useful.

Just by looking at your code and the docs, I wonder whether you are just missing the <fromSchema> tag?


Renaming a table:

<renameMappings>
  <renameMapping>
    <fromSchema>PROD</fromSchema>
    <fromTable>CUSTOMER</fromTable>
    <toTable>CSTMR</toTable>
  </renameMapping>
</renameMappings>




Regards
Luisa
Message has been deleted

Maths

unread,
Dec 9, 2019, 10:58:28 AM12/9/19
to Querydsl
Hi Luisa,

Thanks for your answer.

I have no errors, just my table is not rename (I got QSuiTrLog). => Maybe I don't understand how it's working ?
My objective : if the name of my table change, I don't want to change my code (only change the pom).

I try also with <fromSchema> tag but it doesn't work and in the doc : "Note: fromSchema can be omitted when renaming tables and columns." http://www.querydsl.com/static/querydsl/4.2.1/reference/html/ch02s03.html

Regards,
Fabien

xtre...@gmail.com

unread,
Dec 9, 2019, 11:04:51 AM12/9/19
to Querydsl on behalf of Maths

Hi,

 

So if you run the Maven job in verbose mode, it does not throw any related error?

 

If you don’t get anywhere, perhaps consider codegen programmatically, so that you can just run a class which will updates your table beans whenever you make changes to your DB.

 

Regards

Luisa

 

 

Sent from Mail for Windows 10

--
You received this message because you are subscribed to a topic in the Google Groups "Querydsl" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/querydsl/s1AJbJJ6jxM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to querydsl+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/querydsl/757468db-2f84-49f6-af1b-48059685dd6c%40googlegroups.com.

 

xtre...@gmail.com

unread,
Dec 9, 2019, 11:14:28 AM12/9/19
to Querydsl on behalf of Maths

Ps

I am assuming that by renaming a table you mean represent a table called A in your DB as something called B in your code.

That is my understand of what a mapping should do, it will not rename the table name in your db itself.

If find evidence of otherwise  please let me know

 

 

Sent from Mail for Windows 10

 

From: Maths via Querydsl
Sent: 09 December 2019 15:58
To: Querydsl
Subject: Re: Querydsl - sql : Rename a table

 

Hi Luisa,

 

Thanks for your answer.

 

I have no errors, just my table is not rename (I got QSuiTrLog). => Maybe I don't understand how it's working ?

My objective : if the name of my table change, I don't want to change my code (only change the pom).

 

I try also with <fromSchema> tag but it doesn't work and in the doc : "Note: fromSchema can be omitted when renaming tables and columns." http://www.querydsl.com/static/querydsl/4.2.1/reference/html/ch02s03.html

 

Regards,

Fabien

--

You received this message because you are subscribed to a topic in the Google Groups "Querydsl" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/querydsl/s1AJbJJ6jxM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to querydsl+u...@googlegroups.com.

Maths

unread,
Dec 10, 2019, 4:05:42 AM12/10/19
to Querydsl
Hi,
 
Yes I want it, change the class name in my code.
 
Message has been deleted

Maths

unread,
Dec 10, 2019, 4:09:06 AM12/10/19
to Querydsl
Ok I will try it (I'm beginner in Maven).

Luísa Pinto

unread,
Dec 10, 2019, 4:23:29 AM12/10/19
to Querydsl on behalf of Maths
Hi

Dont worry about it. Glad to help.

I think you will be looking for option -X before the goal. 

Cheers!

--
You received this message because you are subscribed to a topic in the Google Groups "Querydsl" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/querydsl/s1AJbJJ6jxM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to querydsl+u...@googlegroups.com.

Maths

unread,
Dec 13, 2019, 10:30:33 AM12/13/19
to Querydsl
Hi,

I must change to ant build (some problems in deployment with maven, can't access to database with jenkins).

I have the same problem, my ant configuration :

<target name="codegen">
<taskdef name="codegen" classpathref="pacifique-socle-batch-app.module.classpath"
classname="com.querydsl.sql.codegen.ant.AntMetaDataExporter"/>
<codegen
jdbcDriver="org.postgresql.Driver"
jdbcUser="postgres"
jdbcPassword="root"
jdbcUrl="jdbc:postgresql://localhost:5432/pacifique"
packageName="empty"
targetFolder="build"
tablenamepattern="sui\_t\_%,ref_tr_contexte,exp_moo_t_security"
exportinverseforeignkeys="false"
innerclassesforkeys="true">
<renamemapping fromschema="public" toschema="pub"/>
<renamemapping fromschema="PUBLIC" toschema="PUB"/>
<renamemapping fromschema="PUBLIC" fromtable="SUI_T_FLUX" toschema="PUB" totable="QFlux1"/>
<renamemapping fromschema="public" fromtable="sui_t_flux" toschema="pub" totable="QFlux2"/>
<renamemapping fromschema="public" fromtable="QSuiTFlux" toschema="pub" totable="QFlux3"/>
</codegen>
</target>

And the result :

But generation QSuiTFlux.java and don't rename schema (my schema change in other environments) :
public QSuiTFlux(String variable) {
super(QSuiTFlux.class, forVariable(variable), "public", "sui_t_flux");
addMetadata();
}

Maybe I will change generated class after...

Cheers,
Fabien

Maths

unread,
Dec 13, 2019, 11:15:27 AM12/13/19
to Querydsl
It will be better if querydsl-sql code generation works like querydsl-jpa... Don't need database connection to generate classes, and with project with both technologies, need only 1 class for 1 table.

I have change generated code to delete schema "public" and put it in parameter.
It works but need to change the code :/
Reply all
Reply to author
Forward
0 new messages