Avoid generating header comments with Hibernate generation tools - eclipse

When generating DTO objects, hibernate tools generate comments in the header:
// Generated 22 avr. 2013 20:29:27 by Hibernate Tools 3.4.0.CR1
Every generation the comments change (as they contains the generation date/time).
The problem is that in my SVN I end up having many non-usefull changes, so I have to check every single generated file to see whether to commit (if it contains actuals changes) or override it (if it's only the header).
Is there a way to avoid generating said header ?
Thank you.

You would have to customize the Freemarker template which is found in hibernate-tools.jar. Navigate to the /pojo/Pojo.ftl and remove the line // Generated ${date} by Hibernate Tools ${version}.
Checking this out might help: https://forum.hibernate.org/viewtopic.php?f=6&t=989777&view=next
An example of a Hibernate tool Ant task (by specifying templatepath and hbmtemplate attributes:
<hibernatetool destdir="hibernate-model-gen/pojo" templatepath="hibernate-model-gen/customized-templates">
<jdbcconfiguration configurationfile="hibernate-model-gen/hibernate.cfg.xml" packagename="open.pub.proto.core.model" revengfile="hibernate-model-gen\gen-conf\hibernate.reveng.xml" detectmanytomany="true" />
<hbmtemplate templateprefix="pojo/" template="pojo/Pojo.ftl" filepattern="{package-name}/{class-name}.java">
<property key="jdk5" value="true" />
<property key="ejb3" value="true" />
</hbmtemplate>
</hibernatetool>

Related

Mybatis Generator's bug: configuration items should be ordered?

If I put "<commentGenerator>" after "<jdbcConnection>", MBG proposed an error that context content should match: blablabla...
But when I put "<commentGenerator>" before "<jdbcConnection>", everything is ok. Here I have something to complain to the official website that if the order of these items is need, why you do not tell us! What an important thing! You r kidding the freshmen. Maybe it is some where I do not know, but this is a key point to build the MBG's configuration file successfully, why not put this NOTE on the top of the tutorial or somewhere eye-catching?
<generatorConfiguration >
<classPathEntry location="D:\mariadb-java-client-1.1.7.jar" />
<context id="db" >
<commentGenerator>
<property name="suppressAllComments" value="true" />
<property name="suppressDate" value="true" />
</commentGenerator>
<jdbcConnection driverClass="org.mariadb.jdbc.Driver"
connectionURL="jdbc:mariadb://localhost:3306/dbname"
userId="root"
password="password"
/>
<javaTypeResolver >
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- Model Class -->
<javaModelGenerator targetPackage="org.infrastructure.model" targetProject="infrastructure\src\main\java">
<property name="enableSubPackages" value="false" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- XML Files -->
<sqlMapGenerator targetPackage="sqlMap" targetProject="infrastructure\src\main\config">
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<!-- DAO -->
<javaClientGenerator type="XMLMAPPER" targetPackage="org.infrastructure.dao" targetProject="infrastructure\src\main\java">
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<!-- Tables -->
<table tableName="user" domainObjectName="User" ></table>
</context>
</generatorConfiguration>
First of all, in your xml configuration file, it doesn't contains a valid root element, which always should be like <!DOCTYPE .../>. About how to add a correct root element of mybatis generator configuration file, please see example from MyBatis GeneratorXML Configuration File Reference.
If you correctly specified root element such as following:
<!DOCTYPE generatorConfiguration PUBLIC
"-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"
>
This root element contains a typical DTD declaration located at http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd. This is the definition of the order of these items is need. And we are going to see what it looks like.
From line 47 of this document type definition, it defines element named context. The content is as following:
<!--
The context element is used to describe a context for generating files, and the source tables.
-->
<!ELEMENT context (property*, plugin*, commentGenerator?, jdbcConnection, javaTypeResolver?,javaModelGenerator, sqlMapGenerator?, javaClientGenerator?, table+)>
Which obviously defined the order of the element in context, that is:
property*, plugin*, commentGenerator?, jdbcConnection,
javaTypeResolver?,javaModelGenerator, sqlMapGenerator?,
javaClientGenerator?, table+
In this element, all children must occurs as following rules:
+ for specifying that there must be one or more occurrences of the item — the effective content of each occurrence may be different;
* for specifying that any number (zero or more) of occurrences is allowed — the item is optional and the effective content of each occurrence may be different;
? for specifying that there must not be more than one occurrence — the item is optional;
If there is no quantifier, the specified item must occur exactly one time at the specified position in the content of the element.
After we understanding its real meaning, why you could not change the order of commentGenerator and jdbcConnection should be clear.
Maybe you want to know how to make the element out of order, question How to define DTD without strict element order could be useful.
Wish it helpful.

How to create a repository in ATG?

i would like to know how to create a new repository in ATG. like what all steps are needed to be included? Do i need to create a properties file?
In order to create a new repository, You need to follow these steps if you want to create a repository that uses sql database in as the datastore.
Create a properties file
Create tables you want to map to the repository
Create a definition XML files to map repository item-descriptors and their properties to the respective tables.
MyRepository.properties
$class=atg.adapter.gsa.GSARepository
repositoryName=MyRepository
definitionFiles=atg/test/repositories/MyRepository.xml
XMLToolsFactory=/atg/dynamo/service/xml/XMLToolsFactory
transactionManager=/atg/dynamo/transaction/TransactionManager
idGenerator=/atg/dynamo/service/IdGenerator
dataSource=/atg/dynamo/service/jdbc/JTDataSource
lockManager=/atg/dynamo/service/ClientLockManager
The above properties files ensures that a new repository component is created and MyRepository.xml will be marked as its definition file.
The content of the MyRepository.xml file should be something like below...
MyRepository.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE gsa-template SYSTEM "http://www.atg.com/dtds/gsa/gsa_1.0.dtd">
<gsa-template>
<header>
<name>New Repository creation</name>
<author>Jyothi Prasad Buddha</author>
</header>
<item-descriptor name="myRepo" cache-mode="simple">
<table name="my_repo" type="primary" id-column-names="id">
<!-- properties that may (or may not) be used as primary keys -->
<property name="name" data-types="String" />
<property name="age" data-types="int" />
</table>
</item-descriptor>
</gsa-template>
However you will have to create the the necessary tables before you start atg instance. The above xml files refers to a table named my_repo which has comlumns name and age.
Yes you need to create properties file's for more details you can read RepositoryGuide.pdf from Oracle.
for more detail you can read below blog
http://immuraliraj.blogspot.in/2011/12/atg-repository-basic-concepts.html
Just type
"ATG Creating a repository" on Google
and you would get lot of relevant results on the first page itself. Also be specific which version of ATG are you using, and what you have already done/found in your research. (just a suggestion, so you get good responses).
Yes, you need a properties file when creating a custom repository component. There are a lot of blogs that answer your question with detailed steps.
Check this for example

Eclipse XML formatting breaks / changes value of list of Spring XML

I have a spring list defined in xml as -
<list>
<value> </value>
</list>
However, Eclipse (Juno) has decided to format it as -
<list>
<value>
</value>
</list>
Therefore, changing my value to space + line break for any developer that might format the XML using Eclipse.
I don't want to change the Eclipse formatting rules, but how do I change the Spring XML to avoid this issue? Is there an attribute I can use instead to store the value? Thanks.
Check the schema, or use xml:space. http://www.simonstl.com/xmlprim/xmlupdate/atts.html

How do I manually edit table mappings in ADO.NET in Visual Studio 2010?

I can't seem to find the answer to what I think is an easy question. I have a Entity model I just created and I want to set the name of the table and the columns by hand. I can see the "mapping details," but how do I edit them or add to them?
It appears the answer is, you can't without going into the XML. You can use the Entity Framework Power Pack to customize the templates for generation, but there's no direct GUI for editing the mappings.
I open the folder where edmx file in, look into all files in it, and find a possible solution.
I advice install the notepad++ first, then right click on the Edmx File in file explorer, and click Edit with Notepad++ then the xml file content will show, or you can directly open the Edmx file by notepad.exe
You'll see something like this on the top part of the file:
<EntityType Name="DataTableName">
<Key>
<PropertyRef Name="id" />
</Key>
<Property Name="DataColumn1" Type="bigint" Nullable="false" />
<Property Name="DataColumn2" Type="datetime" Nullable="false" />
<Property Name="DataColumn3" Type="nvarchar" MaxLength="255" />
<Property Name="DataColumn4" Type="nvarchar" MaxLength="255" />
</EntityType>
What I want to do is remove DataColumn4, I first open the Edmx File in VS and directly click on the column name in the VS UI and press Delete on the keyboard, and you'll find that in the Mapping Detail Window, the right side of DataColumn4 property will be empty, but in the left side the DataColumn4 still exist.
Then, Open the edmx file using Step 1, remove the property in the Step 2 and save the file.
Remove--> <Property Name="DataColumn4" Type="nvarchar" MaxLength="255" />
Restart visual studio, and open the edmx again you'll find DataColumn4 disappear, and I try connect to DB and manipulate Data, works fine.
If you have your .edmx file open in Visual Studio, you should be able to simply right-click on a table or a column in the table and choose 'rename'. Once you change the name it will be reflected in the Mapping Details window.
You can edit the names easily... just click on the name (when the item is already selected) in the 'class diagram' or the table representation in the edmx file and type the new name. If the text does not become selected and editable when you click on it, you can press F2, the standard Windows key to raname an object. Note: you cannot edit the name in the mapping window.
After editing the names, you can right click on the entity and select 'Generate Database from Model...' option to update the names in the database.
Also, see this post for more information.
Here a solution that works on VS 2010. If you Rename an entry, afterwards run "Generate Database from Model..." two times. IN the first run, the mapping is adjusted but you still get a (let me say "compiler") error. In the second run, everything is fine.
I just tested it two times. Worked perfectly.

Jasper report using same template to render in CSV and PDF formats

We are using one template to render the report in CSV and PDF format. But the problem is we need to have report split into pages in PDF but not in CSV. Is it possible to alter the rendering options based on the format in one template. So that we have CSV without pagination information and PDF divided into page. In such a case 2 separate templates one for CSV and one for PDF should be used? or this can be achieved using one template?
Finally found the answer. In the template following properties need to be set
<property name="net.sf.jasperreports.export.csv.exclude.origin.keep.first.band.columnHeader" value="columnHeader" />
<property name="net.sf.jasperreports.export.csv.exclude.origin.band.columnFooter" value="columnFooter" />
<property name="net.sf.jasperreports.export.csv.exclude.origin.band.pageFooter" value="pageFooter" />
<property name="net.sf.jasperreports.export.csv.exclude.origin.band.lastPageFooter" value="lastPageFooter" />
<property name="net.sf.jasperreports.export.csv.exclude.origin.band.summary" value="summary" />
Using JRCsvMetadataExporter solved similar problem. This class extracts the data from the template ignoring the rendering part. Check out the sample here