How to programmatically generate POJO classes for sleep mode?

Hi, I know the Hibernate Eclipse plugin that helps us (through a series of screens and clicks of buttons) generate POJO and DAO classes for base tables. But I would like to emulate this in the runtime, that is, I would like to take the exact steps programmatically, where I would have to provide the .cfg.xml file, reveng.xml file, database URL, destination folder, via the / parameters inside the main (String [] args) ..

Apparently, there is no such tool that works in a pure hibernation scenario. There is one that is set up to create code for the spring frame, but is not directly in use right now.

I tried downloading the hibernate-tools.jar source code for the eclipse plugin, but right now the link to download the src code on hibernate.org (new design) was disabled for some reason.

Has anyone handled such a thing before? Or can you give me some tips to do this?

I tried a specific object of the JDBCReader class, the explanation of which was read by all tables using the JDBCReader methods, and then figure out how to use the hbm2POJO generator class ....

+3
source share
3 answers

, .cfg.xml, reveng.xml, URL- , , / main (String [] args)

Eclipse Ant Eclipse, Ant, Eclipse Ant, , "" ( , , , ).

hibernate-tools.jar eclipse, src hibernate.org( ) - .

Hibernate Tools Jvoss subversion. , : http://anonsvn.jboss.org/repos/hibernate/trunk/HibernateExt/tools/. , , org.hibernate.tool.hbm2x.*.

+3

, ant task. ant , org.hibernate.tool.ant.HibernateToolTask execute(). , .

. , , .

+3

pojos, maven-antrun-plugin pom.xml.

<build>
    ...
    <plugins>
       <plugin>
          <artifactId>maven-antrun-plugin</artifactId>
          <executions>
            <execution>
              <phase>generate-sources</phase>
              <configuration>
                <tasks>
                  <taskdef name="hibernatetool"
                           classname="org.hibernate.tool.ant.HibernateToolTask"
                           classpathref="maven.dependency.classpath"/>

                  <hbm2java output="src/generated">
                      <fileset dir="src/hibernate">
                          <include name="**/*.hbm.xml"/>
                      </fileset>
                  </hbm2java>
                </tasks>
              </configuration>
              <goals>
                <goal>run</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
     </plugins>
  </build>

pojo, Hibernate, . git pojos hbm.

0
source

Source: https://habr.com/ru/post/1739876/


All Articles