JPA using Hibernate and mysql in Netbeans 8.1

Part 1

Part 2

General steps taken in the video above.(Not the exact steps)

  1. Create database jpa_1:
  2. create database jpa_1;

  1. Configure Netbeans 8.1 to have the database in services:
  2. Database: jpa_1
    url: jdbc:mysql://localhost:3306/jpa_1
    username: greenhorn

  1. Create a maven java application in Netbeans 8.1.

  1. Add maven dependencies into pom.xml:
  2. <dependencies>

    <!– for JPA, use hibernate-entitymanager instead of hibernate-core –>
       <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-entitymanager</artifactId>
          <version>5.0.6.Final</version>
       </dependency>

       <dependency>
          <groupId>mysql</groupId>
          <artifactId>mysql-connector-java</artifactId>
          <version>5.1.37</version>
       </dependency>

       <dependency>
          <groupId>javax.transaction</groupId>
          <artifactId>jta</artifactId>
          <version>1.1</version>
       </dependency>

    </dependencies>

  1. Add class, Book.java from Netbeans “New” right click option. Includes the below instance variable.
  2. private String name;

  1. Add class, Student.java from Netbeans “New” right click option. Includes the below instance variables.
  2. private String firstName;

    private String lastName;

    @OneToMany(cascade = CascadeType.ALL)
    @JoinColumn(name = “student_id”)
    private Set<Book> books = new HashSet<Book>();

  1. Generate getter and setter methods for the instance variables in Student and Book class from Netbeans.

  1. Add class, Main.java from Netbeans “New” right click option. Includes the below main method.
  2. public static void main(String[] args) {
         EntityManagerFactory entityManagerFactory =
         Persistence.createEntityManagerFactory(“abc”);
         EntityManager entityManager = entityManagerFactory.createEntityManager();
         entityManagerFactory.close();
    }

  1. Clean the pom file. It should look similar to the below:
  2. <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>org.greenhorn</groupId>
        <artifactId>jpa1</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>jar</packaging>
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
        </properties>

        <dependencies>

            <!-- for JPA, use hibernate-entitymanager instead of hibernate-core -->
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-entitymanager</artifactId>
                <version>4.3.1.Final</version>
            </dependency>

            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.37</version>
            </dependency>

            <dependency>
                <groupId>javax.transaction</groupId>
                <artifactId>jta</artifactId>
                <version>1.1</version>
            </dependency>
        </dependencies>
    </project>

  1. Run Main class from Netbeans 8.1


NOTE
The sample maven project used for this exercise can be downloaded from

jpa1

spring-boot-starter-web with Maven and Netbeans 8.1 (With executable jar)

General steps taken in the video above.

1) Starts here: spring-boot
2) Use the other getting-started: spring-boot in docs
3) Skip to “11. Developing your first Spring Boot application”
4) Add “spring-boot-starter-web” dependency.
5) Copy code.
6) Run directcly from netbeans or “mvn spring-boot:run”
7) Executable jar
8) Run java -jar target/spring-2-1.0-SNAPSHOT.jar
9) End

spring-boot-starter-web with Maven and Netbeans 8.1

General steps taken in the video above.

1) Starts here: spring-boot

maven java web application with maven tomcat plugin

Part 1

Part 2

General steps taken in the video above.(Not the exact steps)

1) Create project in Netbeans.
2) Check out the plugin from apache tomcat page.
3) Changing pom to include “Apache Tomcat Maven Plugin”.
4) Run using apache tomcat maven goal.
5) Test deployment.
5) Add new servlet to project and use annotation instead of web.xml configuration.
6) Test servlet.
7) Enable contextReloadable for tomcat maven plugin:

<configuration>
	   <contextReloadable>true</contextReloadable>
</configuration>

8) Test contextReloadable.

NOTE
The sample maven project used for this exercise can be downloaded from:

tomcatA

Installing nodejs and npm on Ubuntu 14.04 LTS

Installing git on ubuntu 14.04 LTS

Connecting remote mysql database using ssh tunnel


The command used to create remote ssh tunnel(sample):

ssh -L 3306:localhost:3306 greenhorn@192.168.1.254

Command used to connect to server using ssh:

ssh greenhorn@192.168.1.254.com

Command to connect to database using user “greenhorn”:

mysql -u greenhorn -p

Command to use a database in particular. In this case I’m using “greenhornDb”:

use greenhornDb;

To show all the tables in the selected database I used command:

show tables;

WARNING:
If you have local mysql running on the same port 3360. You need to stop it first.

Reference:
access-your-mysql-server-remotely-over-ssh

End process running on specific port in Windows 8.1



The command used to view all the ports in use:

netstat -a -o -n

The command used to terminate a process:

taskkill /F /PID <PID-to-be-terminated>

Reference:
kills-the-process-at-a-certain-port-in-windows-7

Installing Selenium IDE on firefox and recording your first script

How to change password of mysql user with existing password

Changing the existing user “greenhorn” password.

  1. Login to mysql using root user(your root user could be different from the one below):
  2. mysql -u root -p

  1. Change user password which uses “localhost” host.:
  2. set password for ‘greenhorn’@’localhost’= password(‘test1234’);

  1. Change user password which uses “%” host.:
  2. set password for ‘greenhorn’@’%’= password(‘test1234’);