0

There's a lot of new things I'm using in a new project that I'm unfamiliar with and I need some hand-holding. Maven, Hibernate and Spring in Netbeans 8.2. I'm familiar with Netbeans but the others are new.

I've been using this tutorial as a reference to get things going and I've gotten the hang of a lot of things https://howtodoinjava.com/spring5/webmvc/spring5-mvc-hibernate5-example/

Everything is working and I was able to generate the mappings and POJO's using the Netbeans wizard which was nice but one thing that's slowing me down is the DAO's.

Is there some way to automatically generate the DAO's for hibernate so there are standard CRUD capabilities and I can add where criteria?

I saw something about hbm2dao and hbm2java but they only showed snippets of the pom.xml which wasn't enough for me to understand given my limited time with Maven.

Here's my pom.xml can someone please modify it so that it can generate the dao's and highlight what they did and why? Any changes outside pom.xml if necessary too.

If there's a better way to do it within NetBeans I'm open to other options but I don't want to throw a lot more complexity into the mix.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.myproject</groupId>
    <artifactId>MyProject</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>MyProject</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        <spring.version>5.0.0.RELEASE</spring.version>
        <!--<hibernate.version>5.2.11.Final</hibernate.version>-->
        <!--<hibernate.validator>5.4.1.Final</hibernate.validator>-->
        <hibernate.version>5.3.6.Final</hibernate.version>
        <hibernate.validator>6.0.13.Final</hibernate.validator>
        <c3p0.version>0.9.5.2</c3p0.version>
        <jstl.version>1.2.1</jstl.version>
        <tld.version>1.1.2</tld.version>
        <servlets.version>3.1.0</servlets.version>
        <jsp.version>2.3.1</jsp.version>
        <mysql.version>8.0.12</mysql.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.3.1.Final</version>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <!-- Spring MVC Dependency -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <!-- Spring ORM -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <!-- Hibernate Core -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <!-- Hibernate-C3P0 Integration -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-c3p0</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <!-- c3p0 -->
        <dependency>
            <groupId>com.mchange</groupId>
            <artifactId>c3p0</artifactId>
            <version>${c3p0.version}</version>
        </dependency>

        <!-- Hibernate Validator -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>${hibernate.validator}</version>
        </dependency>

        <!-- JSTL Dependency -->
        <dependency>
            <groupId>javax.servlet.jsp.jstl</groupId>
            <artifactId>javax.servlet.jsp.jstl-api</artifactId>
            <version>${jstl.version}</version>
        </dependency>

        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>${tld.version}</version>
        </dependency>

        <!-- Servlet Dependency -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>${servlets.version}</version>
            <scope>provided</scope>
        </dependency>

        <!-- JSP Dependency -->
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>javax.servlet.jsp-api</artifactId>
            <version>${jsp.version}</version>
            <scope>provided</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
        </dependency>
        <!--Added this because getting an error java.lang.NoSuchMethodError: org.hibernate.internal.CoreMessageLogger.debugf site:stackoverflow.com-->
        <dependency>
            <groupId>org.jboss.logging</groupId>
            <artifactId>jboss-logging</artifactId>
            <version>3.3.0.Final</version>
        </dependency>


    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>7.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>
OrganicLawnDIY
  • 153
  • 1
  • 9
  • Does this help?... [Making java Entity classes from MySQL tables in netbenas](https://stackoverflow.com/q/52428654/2985643). – skomisa Sep 21 '18 at 19:28
  • @skomisa Maybe it should but I'm not seeing it. I already tried that. It generates a mix of what looks like a DTO(Pojo) and DAO but it doesn't have insert/update methods. I got the DTO part by using the wizard that generates hibernate mapping files and POJOS (see https://netbeans.org/kb/docs/web/hibernate-webapp.html#05) but then they manually create a "Helper" class with the query logic. This question is related but my limited familiartiy has me lost it's missing pieces https://stackoverflow.com/questions/2843949/how-to-configure-hibernate-tools-with-maven-to-generate-hibernate-cfg-xml-hbm – OrganicLawnDIY Sep 21 '18 at 20:13
  • @skomisa I'm getting close but not all pieces there yet. Add hibernate3 to dependencies (https://mvnrepository.com/artifact/org.codehaus.mojo/hibernate3-maven-plugin/3.0) that has hbm2dao then I need to set up the plugin and execution in the pom and add the execution in an action when I go to project properties. I can get it to run but it's not generating files. – OrganicLawnDIY Sep 21 '18 at 20:48
  • OK, can you clarify this: _"I can get it to run but it's not generating files"_? Are any warnings or errors being logged? – skomisa Sep 21 '18 at 21:06
  • One more thing to try with NetBeans, assuming that you already have some entity class(es): in the **Projects** panel select the target package for your DTO(s), right-click and select **New > Other... > Categories > Persistence > JPA Controller Classes from Entity Classes**, and then go through the wizard to generate the class(es). So for example, if you have an entity/class named **Widget** it will generate a class named **WidgetJpaController** with methods supporting CRUD operations (_create()_, _edit()_, _destory()_, etc.). Is that what you are looking for? – skomisa Sep 21 '18 at 21:25
  • I don't have entity classes that the wizard recognizes. I created a test project and generated the entity classes and controller classes. Kind of what I'm looking for except it has limited methods and bypasses hibernate doesn't it? I wrote my own persistence tools before JPA was finalized but trying to use more conventional tools. What I did was run 3 hibernate wizards from New -> Other... Hibernate Configuration Wizard, Hibernate Reverse Engineering Wizard then Hibernate Mapping Files and POJOs from Database. Those files don't have the Annotations that would let JPA CC from EC run on them. – OrganicLawnDIY Sep 21 '18 at 22:03
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/180556/discussion-between-organiclawndiy-and-skomisa). – OrganicLawnDIY Sep 21 '18 at 22:03
  • OK...I'll dig deeper later, but can't chat right now. – skomisa Sep 21 '18 at 22:14

0 Answers0