hbm.xml to annotations

sebastianb

Erfahrenes Mitglied
Hi zusammen,

ich arbeite derzeit an einer Migration von Hibernate-XDoclet Annotations zu regulären Annotations. Da ich das Ganze ein wenig automatisieren möchte, wäre es nicht schlecht, wenn es einen Weg geben würde aus denen von XDoclet generierten *hbm.xml Dateien regülare Annotations zu generieren. Kennt hierzu jemand eine schöne Lösung?

Viele Grüße

Sebastian
 
Hi,

so aktuell bin ich soweit, dass ich mir ein Pojo mit JPA-Annotations aus den hbms generieren kann.

Code:
			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>hibernate3-maven-plugin</artifactId>
				<version>2.2</version>
				<executions>
					<execution>
						<id>hbm2java</id>
						<phase>generate-sources</phase>
						<goals>
							<goal>hbm2java</goal>
						</goals>
						<configuration>
							<components>
								<component>
									<name>hbm2java</name>
									<implementation>configuration</implementation>
									<outputDirectory>/src/main/java</outputDirectory>
								</component>
							</components>
							<componentProperties>
								<jdk5>true</jdk5>
								<ejb3>true</ejb3>
								<update>true</update>
								<format>true</format>
								<configurationfile>/src/main/resources/hibernate.cfg.xml</configurationfile>
							</componentProperties>
						</configuration>
					</execution>
				</executions>
			</plugin>

Das Problem, dass sich jetzt nun aber stellt ist, dass ich die Annotations in die Ursprungsdatei "mergen" muss. Hierzu habe ich zunächst den JAVA-/AST-Parser von http://code.google.com/p/javaparser/ verwendet und alles schien zu funktionieren, jedoch habe ich bemerkt, dass der Parser Kommentare ignoriert. Da dies für mich ein klarer Blocker ist bin ich nun zum Eclipse Parser gewechselt. Leider komme ich aufgrund dessen hoher Komplexität nur bedingt vorran und ich bin immer noch auf der Suche, wie ich mir die Annotations einer Methode geben lassen kann. Falls jmd. von euch ein kleines Howto hierzu hat wäre ich sehr dankbar.

Viele Grüße

Sebastian
 
Zuletzt bearbeitet:
One of the most frustrating part of modifying an AST is the comment handling. The method CompilationUnit#getCommentList() is used to return the list of comments located in the compilation unit in the ascendant order. Unfortunately, this list cannot be modified. This means that even if the AST Rewriter is used to add a comment inside a compilation unit, the new comment would not appear inside the comments' list.

http://www.eclipse.org/articles/article.php?file=Article-JavaCodeManipulation_AST/index.html

Schade...

Gruß

Sebastian
 
Zurück