HBM2Java uses default plattform encoding for source generation

Description

I am using hbm2java via Maven integration in a project where we are doing database first development. I have used a custom ReverseEngineeringStrategy in order to import the comments from tables and fields into the generated classes.

The project language is spanish, so usually the comments in the database will contain characters with accents (á, é, í…) etc. When the code is generated, it will produce errors because the files have the wrong encoding and these characters are mangled.

I took a look at the hbm2x sources and turns out that the code that does the actual writing of the files looks as follows (in the class org.hibernate.tool.hbm2x.TemplateProducer) :

fileWriter = new FileWriter(destination);
fileWriter.write(tempResult);

The ‘destination’ variable is a File reference, and tempResult is the templates output.

Well, turns out that with this code, java will write the file using the default plattform encoding, which in my case, being a Windows user, will end up being CP-1512.

So, for international character codes support I think this code should at least write UTF-8, or even better, let the user select the encoding.

Environment

None

Activity

Show:
Jordi Hernández
April 11, 2020, 2:38 PM

I created a pull request to solve this issue ( )

Jordi Hernández
April 12, 2020, 8:11 PM

Sorry about this, I created the issue under the wrong project. I have created a new issue for this request where it belongs. Please delete/close this issue. My apologies.

Assignee

Unassigned

Reporter

Jordi Hernández

Labels

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Suitable for new contributors

None

backportDecision

None

backportReEvaluate

None

Priority

Minor
Configure