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.dialect">org.hibernate.dialect.DerbyDialect</property>
<property name="hibernate.connection.driver_class">org.apache.derby.jdbc.ClientDriver</property>
<property name="hibernate.connection.url">jdbc:derby://localhost:1527/hibernate</property>
<property name="hibernate.connection.username">app</property>
<property name="hibernate.connection.password">app</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">update</property>
<mapping class="com.myhb.Address"/>
<mapping class="com.myhb.Employee"/>
</session-factory>
</hibernate-configuration>
Address.java
============
package com.myhb;
import java.io.Serializable;
import javax.persistence.*;
@Entity
@Table(name = "ADDRESSB")
public class Address implements Serializable{
@Id
@Column(name = "ADDRID")
private int addrId;
@Column(name = "LINE1")
private String line1;
@Column(name = "CITY")
private String city;
@Column(name = "PINCODE")
private int pincode;
@OneToOne(targetEntity = Employee.class, cascade = CascadeType.REMOVE)
@JoinColumn(name = "empId_FK" ,referencedColumnName = "empId")
private Employee employee;
public Address(){
}
public Employee getEmployee() {
return employee;
}
public void setEmployee(Employee employee) {
this.employee = employee;
}
public int getAddrId() {
return addrId;
}
public void setAddrId(int addrId) {
this.addrId = addrId;
}
public String getLine1() {
return line1;
}
public void setLine1(String line1) {
this.line1 = line1;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public int getPincode() {
return pincode;
}
public void setPincode(int pincode) {
this.pincode = pincode;
}
public String toString(){
return addrId+" "+line1+" "+city+" "+pincode;
}
}
Employee.java
=============
package com.myhb;
import java.io.Serializable;
import java.util.Objects;
import javax.persistence.*;
@Entity
@Table(name = "EMPLOYEEB")
public class Employee implements Serializable{
@Id
@Column(name = "EMPID")
private int empId;
@Column(name = "EMPNAME")
private String name;
@Column(name = "SALARY")
private float salary;
@OneToOne(targetEntity = Address.class, cascade = CascadeType.ALL)
@JoinColumn(name = "ADDRID_FK", referencedColumnName = "ADDRID")
private Address address;
public Employee(){
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public int getEmpId() {
return empId;
}
public void setEmpId(int empId) {
this.empId = empId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getSalary() {
return salary;
}
public void setSalary(float salary) {
this.salary = salary;
}
@Override
public int hashCode() {
int hash = 3;
hash = 83 * hash + this.empId;
hash = 83 * hash + Objects.hashCode(this.name);
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Employee other = (Employee) obj;
if (this.empId != other.empId) {
return false;
}
if (!Objects.equals(this.name, other.name)) {
return false;
}
return true;
}
}
SaveData.java
=============
package com.myhb;
import org.hibernate.*;
import org.hibernate.cfg.*;
public class SaveData {
public static void main(String[] args) {
SessionFactory factory = new AnnotationConfiguration().configure().buildSessionFactory();
Session session = factory.openSession();
Transaction tx = session.beginTransaction();
Employee emp = new Employee();
Address addr = new Address();
emp.setEmpId(111);
emp.setName("Mohan");
emp.setSalary(20000);
addr.setAddrId(222);
addr.setCity("Bengaluru");
addr.setLine1("MunneKolala");
addr.setPincode(900009);
addr.setEmployee(emp);
emp.setAddress(addr);
session.persist(addr);
session.persist(emp);
tx.commit();
session.close();
// factory.close();
System.out.println("Record saved successfully...");
}
}
DeleteOrUpdate.java
===================
package com.myhb;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
public class DeleteOrUpdate {
public static void main(String[] args) {
SessionFactory factory = new AnnotationConfiguration().configure().buildSessionFactory();
Session session = factory.openSession();
Transaction tx = session.beginTransaction();
Employee emp = (Employee)session.load(Employee.class, 111);
// Address addr = (Address)session.load(Address.class, 888);
// addr.setCity("Delhi");
emp.getAddress().setCity("Hahahaha");
emp.setName("BBBBB");
// session.persist(addr);
session.saveOrUpdate(emp);
// session.update(addr);
tx.commit();
session.close();
System.err.println("Record deleted successfully...");
}
}
FetchData.java
==============
package com.myhb;
import java.util.*;
import org.hibernate.*;
import org.hibernate.cfg.*;
public class FetchData {
public static void main(String[] args) {
SessionFactory factory = new AnnotationConfiguration().configure().buildSessionFactory();
Session session = factory.openSession();
Transaction tx = session.beginTransaction();
Query q = session.createQuery("From Employee");
List list = q.list();
Iterator itr = list.iterator();
while(itr.hasNext()){
Employee emp = (Employee) itr.next();
System.out.println(emp.getEmpId()+" "+emp.getName()+" "+emp.getSalary());
System.out.println("Address : "+emp.getAddress());
}
// System.err.println("Records retrieval over...");
}
}
Followers
Amazon Web Services (AWS)
CoreJava
- coreJava : Core Java Index
- coreJava : Java Basics
- coreJava: Wrapper class
- coreJava: super keyword in java
- coreJava : constructor in java
- coreJava : final key word
- coreJava : this key word in java
- coreJava : packages in java
- coreJava : Access Modifiers in Java
- coreJava : Strings
- coreJava : Exception Handling
- coreJava : Exceptions Handling Interview questions...
- coreJava : Collections
- coreJava : Java Collections Interview Questions
- coreJava : Comparable Vs Comparator
- coreJava: Encapsulation in Java
- coreJava: Threads
- coreJava : Features of java 5.
- coreJava : Features of java
- coreJava : instanceof Operator
Spring IOC
- Spring
- springIOC: Overview and features
- springIOC: Containers
- springIOC: Beans Configuration file
- springIOC: Hello World (XML)
- springIOC: CI with primitive and String
- springIOC: CI with dependent object
- springIOC: CI with Collection
- springIOC: CI with Map
- springIOC: CI with properties
- springIOC: SI with primitive and String
- springIOC: SI with dependent object
- springIOC: SI with collection
- springIOC: SI with map
- springIOC: SI with properties
- springIOC : Difference between constructor and setter injection
- springIOC: Scopes
- springIOC: Spring Scopes(singleton)
- springIOC: Spring Scope (prototype)
- springIOC: Spring Bean Life Cycle
- springIOC: Spring Bean Life Cycle(default init and...
- springIOC: Inheritance(Super class is Abstract Class)
- springIOC: Inheritance(Super class is Concrete Cla...
- springIOC: Multiple Beans using XML (Type1)
- springIOC: Beans Life Cycle (Java)
- springIOC: Multiple Beans using XML (Type2)
- springIOC: Bean Life Cycle(Java Based)
- springIOC : autowire byName
- springIOC : autowire byType
- springIOC : autowire constructor
- springIOC: Hello World (Java Based)
- springIOC: Bean Life Cycle(XML Configuration)
- springIOC : @PostConstruct and @PreDestroy
- springIOC : @Required Annotation
- springIOC : @Autowired on constructor
- springIOC : @Autowired on Setter Method
- springIOC : @Autowired on Field
- springIOC : @Qualifier Annotation
- springIOC : Spring Interview Questions
spring MVC
- springMVC : Controllers
- springMVC : Spring MVC Execution Flow
- springMVC : BasicExample
- springMVC : BasicExample(InternalResourceViewResol...
- springMVC : MultipleRequestsMultipleHandlers
- springMVC : MutipleRequestsOneHandler
- springMVC : uri Template
- springMVC : Exception Handling using Annotation
- springMVC : Exception Handling using Interface
- spring MVC : interceptor
- springMVC : Multiple Interceptor
- springMVC : ResourceBundleViewResolver
- springMVC : Spring and Tiles Integration
- spring MVC : Spring Forms
- springMVC : Spring Form validation Using Validator...
- springMVC : Internationalization Using Automatic A...
- spring application
Spring DAO
- Home
- springdao : Overview Of Spring Dao
- springdao : jdbcTemplate class
- springdao : jdbcTemplate
- springdao : jdbcTemplate(PreparedStatement)
- springdao : jdbcTemplate (Annotation)
- springdao : ResultSetExtractor
- springdao : RowMapper
- springdao : NamedParameterJdbcTemplate
- springdao : SimpleJdbcTemplate
- springdao : Spring and Hibernate Integration
springAOP
- springAOP
- springAOP : Spring AOP Overview
- springAOP : spring AOP with Annotations
- springAOP : @Before
- springAOP : @After
- springAOP : @Around
- springAOP : @AfterThrowing
- springAOP : @AfterReturning
- springAOP : AOP with XML configuration
- springAOP : Before
- springAOP : After
- springAOP : Around
- springAOP : AfterThrowing
- springAOP : AfterReturning
Servlets
- Home
- Servlets : Basics
- Generic Servlet Example
- Servlet: Get Request Handling in Servlets
- Servlet: Post Request Handling in Servlet
- Servlet : load-on-startup / pre initialization of ...
- Servlet: Multiple Buttons in Servlet
- Servlet : ServletConfig
- Servlet: ServletContext
- Servlet : Session tracking techniques in servlet a...
- Servlet: Session tracking using HttpSession
- Servlet: Session tracking using Cookies
- Servlet: Session tracking using URLReWriting
- Servlet: Session tracking using HiddenFormFields
- Servlet: RequestDispatcher
- Servlet: SendRedirect
- Servlet:Filter
- Servlet : AnnotationServlet
JSP
- jsp : Life Cycle and Implicit Objects
- jsp : Scripting tags
- jsp : JSP directive Tags
- JSP:RequestDispatcher
- JSP: SendRedirect
- JSP: Session tracking using Cookies
- JSP: Session tracking using URLRewriting
- JSP: Session tracking using HiddenFormFields
- JSP: Session tracking using HttpSession
- JSP:Exception Handling
- JSP:Custom Tags (TagSupport1)
- jsp : Action Tags
- JSP : Beans in JSP application
- JSP:Custom Tags (TagSupport2)
- JSP:Custom Tags (TagSupport3)
- JSP:Custom Tags (BodyTagSupport)
- JSP:Custom Tags (BodyTagSupport with parameters)
- JSP
JBDC
- JDBC
- JDBC : Insertion using Statement Interface
- JDBC : Updation using Statement Interface
- JDBC : Deletion using Statement Interface
- JDBC: Insertion using PreparedStatement
- JDBC : Updation using PreParedStatement
- JDBC: selection using PreParedStatement
- JDBC: Scrollable Result Set
- JDBC: Updatable ResultSet(Updations)
- JDBC: Updatable ResultSet(Insertions)
- JDBC: Transaction in JDBC
- JDBC : Batch updations
- JDBC : AutoCommit Mode set to False
- JDBC : ResultSetMetaData interface
- JDBC : DatabaseMetaData interface
- JDBC:RowSet usage(JAVA 7 feature)
- JDBC : JDBC Drivers
hibernate
- Home
- hb: Mapping And Configuration Files In Hibernate
- hb : Inserting the records using hibernate
- hb : selecting the single record using hibernate
- hb : updating the single record using hibernate
- hb : deleting the single record using hibernate
- hb : Inserting records using hibernate Annotation
- hb : OneToOne XMl mapping (Unidirectional)
- hb : OneToOne mapping using Annotation (Unidirectional)
- hb : OneToOne XMl mapping (Bidirectional)
- hb : OneToOne mapping using Annotation (Bidirectional)
- hb : One to Many Xml Mapping
- hb : One to Many Using Annotation
- hb : Many to One Xml Mapping
- hb : Many to One to Annotation
- HB: Hibernate One-To-Many Using Annotation:
- hb : Many to Many Xml Mapping
- hb : Many to Many Using Annotation
- hb : Table Per Herarchy (TPH) using XML
- hb : Table Per Hierarchy using Annotation(TPH)
- hb : Table Per Class (TPC) using XMl
- hb : Table Per Class using Annotation(TPC)
- hb : Table Per Sub Class (TPS) using XML
- hb : Table Per Sub Class using Annotation(TPS)
- hb : Hibernate Query Language (HQL)
- hb : HQL NamedQueries Using XML
- hb : HQL NamedQueries Using Annotation
- hb: HCQL (Hibernate Criteria Query Language)
- hb : HCQL(Methods)
- hb : HCQL(Aggregate Functions)
- hb : HCQL(Projections)
- hb : Cache Implementation in Hibernate
- hb : Composite Key Implementation Using XML Mappin...
- hb : Composite Key Implementation Using Annotation...
- hb : Version maintenance in Hibernate
- hb : Hibernate Interview Questions
Interview Questions
Popular Posts
-
Lambda function to stop EC2 instance import boto3 client=boto3.client('ec2') def lambda_handler(event, context): re...
Subscribe to:
Posts (Atom)
No comments:
Post a Comment