Friday, 27 September 2019

Application Development

Maven
  • Multi module project
    • Parent POM
      • Add <modules> tag to add projects
    • Child POM
      • Add <Parent> element with  change group id, artifact id and version of Parent POM
    • If one child is dependent on other then add coordinates to respective POM under dependency section.
  • Install Jars that doesn't have central mvn coordinates 
    • mvn install:install-file -Dfile="D:\softwares\jstl-1.2.jar" -DgroupId=javax.servlet -DartifactId=jstl -Dversion=1.2 -Dpackaging=jar 
Hibernate 4
  1.         <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-core</artifactId>
                <version>4.3.11.Final</version>
            </dependency>
            <dependency>
                <groupId>com.oracle</groupId>
                <artifactId>ojdbc7</artifactId>
                <version>12.2.0.1</version>
            </dependency>
  2.  hibernate.cfg.xml

    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
        <session-factory>
            <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
            <property name="hibernate.connection.url">jdbc:oracle:thin:@slc12lpa.us.oracle.com:1521:orcl</property>
            <property name="hibernate.connection.username">vdesu</property>
            <property name="hibernate.connection.password">vdesu1</property>
            <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
            <property name="hibernate.default_schema">vdesu</property>
            <property name="show_sql">true</property>
            <mapping class="com.venkat.projects.hibernate.Student"></mapping>
        </session-factory>
    </hibernate-configuration>

  3. import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.Transaction;
    import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
    import org.hibernate.cfg.Configuration;
    import org.hibernate.service.ServiceRegistry;

    public class App
    {
        public static void main( String[] args )
        {
            Student student = new Student();
            student.setStudentId(3);
            student.setStudentName("vdesu");
            student.setStudentSubject("CS")
            Configuration cfg = new Configuration();
            cfg.configure();
            ServiceRegistry serReg = new StandardServiceRegistryBuilder().
                        applySettings(cfg.getProperties()).build();
            SessionFactory sessionFactory = cfg.buildSessionFactory(serReg);
            Session session = sessionFactory.openSession();
            Transaction tx = session.beginTransaction();
            session.save(student);
            tx.commit();
            System.out.println("saved");
        }
    }
REST Services
  1. Create Maven project of archetype jersey-quickstart-webapp

No comments:

Post a Comment