Requirement Constraints

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg
Showing posts with label Hibernate Mapping. Show all posts
Showing posts with label Hibernate Mapping. Show all posts

Wednesday, 8 August 2012

Hibernate n+1 problem

Posted on 11:10 by Unknown
First let us try to understand what n+1 Problem in hibernate
Look at this stack overflow thread for examples. One of the example is here
Supplier with a one-to-many relationship with Product. One Supplier has (supplies) many Products.
***** Table: Supplier *****
+-----+-------------------+
| ID | NAME |
+-----+-------------------+
| 1 | Supplier Name 1 |
| 2 | Supplier Name 2 |
| 3 | Supplier Name 3 |
| 4 | Supplier Name 4 |
+-----+-------------------+

***** Table: Product *****
+-----+-----------+--------------------+-------+------------+
| ID | NAME | DESCRIPTION | PRICE | SUPPLIERID |
+-----+-----------+--------------------+-------+------------+
|1 | Product 1 | Name for Product 1 | 2.0 | 1 |
|2 | Product 2 | Name for Product 2 | 22.0 | 1 |
|3 | Product 3 | Name for Product 3 | 30.0 | 2 |
|4 | Product 4 | Name for Product 4 | 7.0 | 3 |
+-----+-----------+--------------------+-------+------------+

Factors:


  • Lazy mode for Supplier set to “true” (default)

  • Fetch mode used for querying on Product is Select

  • Fetch mode (default): Supplier information is accessed

  • Caching does not play a role for the first time the

  • Supplier is accessed

Fetch mode is Select Fetch (default)
// It takes Select fetch mode as a default
Query query = session.createQuery( "from Product p");
List list = query.list();
// Supplier is being accessed
displayProductsListWithSupplierName(results);

// It takes Select fetch mode as a default
Query query = session.createQuery( "from Product p");
List list = query.list();
// Supplier is being accessed
displayProductsListWithSupplierName(results);

select ... various field names ... from PRODUCT
select ... various field names ... from SUPPLIER where SUPPLIER.id=?
select ... various field names ... from SUPPLIER where SUPPLIER.id=?
select ... various field names ... from SUPPLIER where SUPPLIER.id=?

Result:

  • 1 select statement for Product
  • N select statements for Supplier

This is N+1 select problem!
Now let us get to our example.

Environment



  1. Eclipse 3.7 Indigo IDE
  2. Hibernate 4.1.1
  3. JavaSE 1.6
  4. MySQL 5.1


Step 1:


Let us set the environment. Follow this post to set up Hibernate with java in eclipse IDE.


Step 2:


Mysql


image

CREATE TABLE `enumeration` (
`ID` BIGINT(20) NOT NULL AUTO_INCREMENT,
`enumCode` VARCHAR(255) DEFAULT NULL,
`enumType` VARCHAR(255) DEFAULT NULL,
`description` VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=INNODB DEFAULT CHARSET=latin1

insert  into `enumeration`(`ID`,`enumCode`,`enumType`,`description`) values (1,'Mr','TITLE','Mr'),(2,'Miss','TITLE','Miss'),(3,'Master','TITLE','Master');




CREATE TABLE `person` (
`ID` BIGINT(20) NOT NULL AUTO_INCREMENT,
`FirstName` VARCHAR(100) DEFAULT NULL,
`LastName` VARCHAR(100) DEFAULT NULL,
`Email` VARCHAR(100) DEFAULT NULL,
`PERSONAL_TITLE` BIGINT(20) DEFAULT NULL,
PRIMARY KEY (`ID`),
KEY `FK_person` (`PERSONAL_TITLE`),
CONSTRAINT `FK_person` FOREIGN KEY (`PERSONAL_TITLE`) REFERENCES `enumeration` (`ID`)
) ENGINE=INNODB DEFAULT CHARSET=latin1

insert  into `person`(`ID`,`FirstName`,`LastName`,`Email`,`PERSONAL_TITLE`) values (1,'John','Smith','JohnSmith@Yahoo.com',1),(2,'James','William','William@yahoo.com',1),(3,'David','Richard','Richard@Yahoo.com',1),(4,'Daniel','Paul','Daniel@Yahoo.com',1),(5,'Gary','Kevin','Kevin@Yahoo.com',1),(6,'Jose','Larry','Larry@Yahoo.com',1),(7,'Scott','Andrew','Scott@Yahoo.com',1);


CREATE TABLE `userlogin` (
`ID` BIGINT(20) NOT NULL AUTO_INCREMENT,
`LoginID` VARCHAR(100) DEFAULT NULL,
`Password` VARCHAR(100) DEFAULT NULL,
`PersonID` BIGINT(20) DEFAULT NULL,
PRIMARY KEY (`ID`),
KEY `FK_userlogin` (`PersonID`),
CONSTRAINT `FK_userlogin` FOREIGN KEY (`PersonID`) REFERENCES `person` (`ID`)
) ENGINE=INNODB DEFAULT CHARSET=latin1


insert  into `userlogin`(`ID`,`LoginID`,`Password`,`PersonID`) values (1,'user1','Pass1',1),(2,'user2','Pass2',2),(3,'user3','pass3',3),(4,'user4','pass4',4),(5,'user5','pass5',5),(6,'user6','pass6',6),(7,'user7','pass7',7);


Java Bean
image

Enumernation.java


package domain;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.ManyToOne;
import javax.persistence.JoinColumn;

@Entity
@Table(name = "enumeration")
public class Enumeration {

@Id
@GeneratedValue
@Column(name = "ID")
private Integer id;

@Column(name = "ENUMCODE")
private String enumCode;

@Column(name = "ENUMTYPE")
private String enumType;

@Column(name = "DESCRIPTION")
private String description;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getEnumCode() {
return enumCode;
}

public void setEnumCode(String enumCode) {
this.enumCode = enumCode;
}

public String getEnumType() {
return enumType;
}

public void setEnumType(String enumType) {
this.enumType = enumType;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

}


Person.java


package domain;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.ManyToOne;
import javax.persistence.JoinColumn;

@Entity
@Table(name = "enumeration")
public class Enumeration {

@Id
@GeneratedValue
@Column(name = "ID")
private Integer id;

@Column(name = "ENUMCODE")
private String enumCode;

@Column(name = "ENUMTYPE")
private String enumType;

@Column(name = "DESCRIPTION")
private String description;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getEnumCode() {
return enumCode;
}

public void setEnumCode(String enumCode) {
this.enumCode = enumCode;
}

public String getEnumType() {
return enumType;
}

public void setEnumType(String enumType) {
this.enumType = enumType;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

}


userlogin.java


package domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;

@Entity
@Table(name = "userlogin")
public class userlogin {

@Id
@GeneratedValue
private int ID;

@Column(name = "LoginID")
private String LoginID;

@Column(name = "password")
private String password;

@OneToOne(optional = false)
@JoinColumn(name = "PersonID")
private Person person;


public int getID() {
return ID;
}

public void setID(int iD) {
ID = iD;
}

public Person getPerson() {
return person;
}

public void setPerson(Person person) {
this.person = person;
}

public String getLoginID() {
return LoginID;
}

public void setLoginID(String loginID) {
LoginID = loginID;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

}


hibernate.cfg.xml


<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/sampledb</property>
<property name="connection.username">root</property>
<property name="connection.password">123</property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>

<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>



<!-- Mapping Classes -->
<mapping class="domain.userlogin" />
<mapping class="domain.Person" />
<mapping class="domain.Enumeration" />


</session-factory>
</hibernate-configuration>


Test.java


package test;

import java.util.ArrayList;
import java.util.List;
import org.hibernate.Session;
import domain.*;
import HibernateUtilities.*;

public class Test {
public static void main(String[] args) {

Session session = HibernateUtil.beginTransaction();
List<userlogin> people = session.createQuery("FROM userlogin").list();
for(userlogin p : people){
System.out.println(p.getLoginID() + " ! " + p.getPerson().getFirstName() + " ! " + p.getPerson().getPersonalTitle().getDescription());
}
HibernateUtil.CommitTransaction();

}

}

Now let us run the test.java and observe the sql output as follows.


Hibernate: select userlogin0_.ID as ID0_, userlogin0_.LoginID as LoginID0_, userlogin0_.password as password0_, userlogin0_.PersonID as PersonID0_ from userlogin userlogin0_
Hibernate: select person0_.ID as ID1_1_, person0_.FirstName as FirstName1_1_, person0_.LastName as LastName1_1_, person0_.PERSONAL_TITLE as PERSONAL4_1_1_, enumeratio1_.ID as ID2_0_, enumeratio1_.DESCRIPTION as DESCRIPT2_2_0_, enumeratio1_.ENUMCODE as ENUMCODE2_0_, enumeratio1_.ENUMTYPE as ENUMTYPE2_0_ from person person0_ left outer join enumeration enumeratio1_ on person0_.PERSONAL_TITLE=enumeratio1_.ID where person0_.ID=?
Hibernate: select person0_.ID as ID1_1_, person0_.FirstName as FirstName1_1_, person0_.LastName as LastName1_1_, person0_.PERSONAL_TITLE as PERSONAL4_1_1_, enumeratio1_.ID as ID2_0_, enumeratio1_.DESCRIPTION as DESCRIPT2_2_0_, enumeratio1_.ENUMCODE as ENUMCODE2_0_, enumeratio1_.ENUMTYPE as ENUMTYPE2_0_ from person person0_ left outer join enumeration enumeratio1_ on person0_.PERSONAL_TITLE=enumeratio1_.ID where person0_.ID=?
Hibernate: select person0_.ID as ID1_1_, person0_.FirstName as FirstName1_1_, person0_.LastName as LastName1_1_, person0_.PERSONAL_TITLE as PERSONAL4_1_1_, enumeratio1_.ID as ID2_0_, enumeratio1_.DESCRIPTION as DESCRIPT2_2_0_, enumeratio1_.ENUMCODE as ENUMCODE2_0_, enumeratio1_.ENUMTYPE as ENUMTYPE2_0_ from person person0_ left outer join enumeration enumeratio1_ on person0_.PERSONAL_TITLE=enumeratio1_.ID where person0_.ID=?
Hibernate: select person0_.ID as ID1_1_, person0_.FirstName as FirstName1_1_, person0_.LastName as LastName1_1_, person0_.PERSONAL_TITLE as PERSONAL4_1_1_, enumeratio1_.ID as ID2_0_, enumeratio1_.DESCRIPTION as DESCRIPT2_2_0_, enumeratio1_.ENUMCODE as ENUMCODE2_0_, enumeratio1_.ENUMTYPE as ENUMTYPE2_0_ from person person0_ left outer join enumeration enumeratio1_ on person0_.PERSONAL_TITLE=enumeratio1_.ID where person0_.ID=?
Hibernate: select person0_.ID as ID1_1_, person0_.FirstName as FirstName1_1_, person0_.LastName as LastName1_1_, person0_.PERSONAL_TITLE as PERSONAL4_1_1_, enumeratio1_.ID as ID2_0_, enumeratio1_.DESCRIPTION as DESCRIPT2_2_0_, enumeratio1_.ENUMCODE as ENUMCODE2_0_, enumeratio1_.ENUMTYPE as ENUMTYPE2_0_ from person person0_ left outer join enumeration enumeratio1_ on person0_.PERSONAL_TITLE=enumeratio1_.ID where person0_.ID=?
Hibernate: select person0_.ID as ID1_1_, person0_.FirstName as FirstName1_1_, person0_.LastName as LastName1_1_, person0_.PERSONAL_TITLE as PERSONAL4_1_1_, enumeratio1_.ID as ID2_0_, enumeratio1_.DESCRIPTION as DESCRIPT2_2_0_, enumeratio1_.ENUMCODE as ENUMCODE2_0_, enumeratio1_.ENUMTYPE as ENUMTYPE2_0_ from person person0_ left outer join enumeration enumeratio1_ on person0_.PERSONAL_TITLE=enumeratio1_.ID where person0_.ID=?
Hibernate: select person0_.ID as ID1_1_, person0_.FirstName as FirstName1_1_, person0_.LastName as LastName1_1_, person0_.PERSONAL_TITLE as PERSONAL4_1_1_, enumeratio1_.ID as ID2_0_, enumeratio1_.DESCRIPTION as DESCRIPT2_2_0_, enumeratio1_.ENUMCODE as ENUMCODE2_0_, enumeratio1_.ENUMTYPE as ENUMTYPE2_0_ from person person0_ left outer join enumeration enumeratio1_ on person0_.PERSONAL_TITLE=enumeratio1_.ID where person0_.ID=?
user1 ! John ! Mr
user2 ! James ! Mr
user3 ! David ! Mr
user4 ! Daniel ! Mr
user5 ! Gary ! Mr
user6 ! Jose ! Mr
user7 ! Scott ! Mr


Hibernate issues 8 query into mysql to show the output. This is typical n+1 Problem. Now let us solve using fetch join in the query as follows

Now let us change our test.java as follows

package test;

import java.util.ArrayList;
import java.util.List;
import org.hibernate.Session;
import domain.*;
import HibernateUtilities.*;

public class Test {
public static void main(String[] args) {

Session session = HibernateUtil.beginTransaction();
List<userlogin> people = session.createQuery("FROM userlogin u join fetch u.person").list();
for(userlogin p : people){
System.out.println(p.getLoginID() + " ! " + p.getPerson().getFirstName() + " ! " + p.getPerson().getPersonalTitle().getDescription());
}
HibernateUtil.CommitTransaction();

}

}


Now let us run the test.java and observe the sql output as follows.

Hibernate: select userlogin0_.ID as ID0_0_, person1_.ID as ID1_1_, userlogin0_.LoginID as LoginID0_0_, userlogin0_.password as password0_0_, userlogin0_.PersonID as PersonID0_0_, person1_.FirstName as FirstName1_1_, person1_.LastName as LastName1_1_, person1_.PERSONAL_TITLE as PERSONAL4_1_1_ from userlogin userlogin0_ inner join person person1_ on userlogin0_.PersonID=person1_.ID
Hibernate: select enumeratio0_.ID as ID2_0_, enumeratio0_.DESCRIPTION as DESCRIPT2_2_0_, enumeratio0_.ENUMCODE as ENUMCODE2_0_, enumeratio0_.ENUMTYPE as ENUMTYPE2_0_ from enumeration enumeratio0_ where enumeratio0_.ID=?
user1 ! John ! Mr
user2 ! James ! Mr
user3 ! David ! Mr
user4 ! Daniel ! Mr
user5 ! Gary ! Mr
user6 ! Jose ! Mr
user7 ! Scott ! Mr


Now it is perfect. Hibernate use inner join between userlogin and person, because each userlogin must have the reference to  person .

But if you see the output, there is one more select which is coming from our person class where we mapped to another master table called enumeration.


Now let us change our test.java as follows

package test;

import java.util.ArrayList;
import java.util.List;
import org.hibernate.Session;
import domain.*;
import HibernateUtilities.*;

public class Test {
public static void main(String[] args) {

Session session = HibernateUtil.beginTransaction();
List<userlogin> people = session.createQuery("FROM userlogin u join fetch u.person p join fetch p.personalTitle ").list();
for(userlogin p : people){
System.out.println(p.getLoginID() + " ! " + p.getPerson().getFirstName() + " ! " + p.getPerson().getPersonalTitle().getDescription());
}
HibernateUtil.CommitTransaction();

}

}

Now let us run the test.java and observe the sql output as follows.



Hibernate: select userlogin0_.ID as ID0_0_, person1_.ID as ID1_1_, enumeratio2_.ID as ID2_2_, userlogin0_.LoginID as LoginID0_0_, userlogin0_.password as password0_0_, userlogin0_.PersonID as PersonID0_0_, person1_.FirstName as FirstName1_1_, person1_.LastName as LastName1_1_, person1_.PERSONAL_TITLE as PERSONAL4_1_1_, enumeratio2_.DESCRIPTION as DESCRIPT2_2_2_, enumeratio2_.ENUMCODE as ENUMCODE2_2_, enumeratio2_.ENUMTYPE as ENUMTYPE2_2_ from userlogin userlogin0_ inner join person person1_ on userlogin0_.PersonID=person1_.ID inner join enumeration enumeratio2_ on person1_.PERSONAL_TITLE=enumeratio2_.ID
user1 ! John ! Mr
user2 ! James ! Mr
user3 ! David ! Mr
user4 ! Daniel ! Mr
user5 ! Gary ! Mr
user6 ! Jose ! Mr
user7 ! Scott ! Mr


Now it is only one select statement


Finally, what happen if personal_title is optional in person table, we will left outer join as folllows

package test;

import java.util.ArrayList;
import java.util.List;
import org.hibernate.Session;
import domain.*;
import HibernateUtilities.*;

public class Test {
public static void main(String[] args) {

Session session = HibernateUtil.beginTransaction();
List<userlogin> people = session.createQuery("FROM userlogin u join fetch u.person p left outer join fetch p.personalTitle ").list();
for(userlogin p : people){
System.out.println(p.getLoginID() + " ! " + p.getPerson().getFirstName());
}
HibernateUtil.CommitTransaction();

}

}


follow me

<a href="https://plus.google.com/112392680157232301619" rel="author" target="_blank">Follow Me On Google+</a>






Read More
Posted in Hibernate Mapping | No comments

Friday, 3 August 2012

One to many mapping using bidirectional relationship – onetoMany as Owner

Posted on 21:49 by Unknown

First let us look the hibernate documentation on this as follows

To map a bidirectional one to many, with the one-to-many side as the owning side, you have to remove the mappedBy element and set the many to one @JoinColumn as insertable and updatable to false. This solution is not optimized and will produce some additional UPDATE statements.

http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#entity-mapping
http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/

@Entity
public class Troop {
    @OneToMany
    @JoinColumn(name="troop_fk") //we need to duplicate the physical information
    public Set<Soldier> getSoldiers() {
    ...
}

@Entity
public class Soldier {
    @ManyToOne
    @JoinColumn(name="troop_fk", insertable=false, updatable=false)
    public Troop getTroop() {
    ...
}

Now let us goto our example.

In this example, we will see one to many  as owning side i.e master is now owner. As per this example,
Department is  the owner.

image_thumb6

Step : 2

Let us set the environment. Follow this post to set up Hibernate with java in eclipse IDE.

Step : 3

Let us create all our java bean files

Department.java

package domain;


import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Table;
import javax.persistence.OneToMany;

@Entity
@Table(name = "department")
public class Department {

@Id
@GeneratedValue
@Column(name = "ID")
private int ID;

@Column(name = "DepartName")
private String departName;

/**
/* To map a bidirectional one to many, with the one-to-many side as the owning side, you have to remove the mappedBy element and
* set the many to one @JoinColumn as insertable and updatable to false. This solution is not optimized and will produce some
* additional UPDATE statements.
* Using JoinColumn makes the join-table the many side of association.
* Using JoinColumn puts an association into the many side of the one-to-many and it is that column that is used to join the two entities,
* not an extra table.
* http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#entity-mapping
*/

/** I am the owner**/
@OneToMany(cascade={CascadeType.ALL})
@JoinColumn(name="DepartmentID", nullable = false)
List<Employees> employees;

public int getID() {
return ID;
}

public void setID(int iD) {
ID = iD;
}

public String getDepartName() {
return departName;
}

public void setDepartName(String departName) {
this.departName = departName;
}

public List<Employees> getEmployees() {
return employees;
}

public void setEmployees(List<Employees> employees) {
this.employees = employees;
}



}


Employees.java


package domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.ManyToOne;
import javax.persistence.JoinColumn;

import org.hibernate.annotations.ForeignKey;

@Entity
@Table(name = "employees")
public class Employees {

@Id
@GeneratedValue
private int ID;
@Column(name = "firstName")
private String firstName;

@Column(name = "lastName")
private String lastName;

@ManyToOne
@JoinColumn(name = "DepartmentID", insertable = false, updatable = false)
private Department department;

public int getID() {
return ID;
}

public void setID(int iD) {
ID = iD;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public Department getDepartment() {
return department;
}

public void setDepartment(Department department) {
this.department = department;
}

}

hibernate.cfg.xml


 


<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/sampledb</property>
<property name="connection.username">root</property>
<property name="connection.password">123</property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>

<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>



<!-- Mapping Classes -->
<mapping class="domain.Department" />
<mapping class="domain.Employees" />

</session-factory>
</hibernate-configuration>


Test Class


package test;

import java.util.ArrayList;
import java.util.List;
import org.hibernate.Session;
import domain.*;
import HibernateUtilities.*;

public class Test {

public static void main(String[] args) {

addNewMasterAndDetail();

}

public static void addNewMasterAndDetail()
{
// Now let us create Department
Department d1 = new Department();
d1.setDepartName("Accounts");

// Now let us some employees
List<Employees> empList = new ArrayList<Employees>();
Employees e1 = new Employees();

e1.setFirstName("John");
e1.setFirstName("Mike");
e1.setDepartment(d1);
empList.add(e1);

e1 = new Employees();
e1.setFirstName("Smith");
e1.setFirstName("Robert");
e1.setDepartment(d1);
empList.add(e1);

d1.setEmployees(empList);

Session session = HibernateUtil.beginTransaction();
session.save(d1);
HibernateUtil.CommitTransaction();

}

}


Now let us run our test.java and let us the look output.

Hibernate: insert into department (DepartName) values (?)
Hibernate: insert into employees (firstName, lastName, DepartmentID) values (?, ?, ?)
Hibernate: insert into employees (firstName, lastName, DepartmentID) values (?, ?, ?)
Hibernate: update employees set DepartmentID=? where ID=?
Hibernate: update employees set DepartmentID=? where ID=?


Now let us do some research and understand the concept.


In this department.java, you can see how we declare the one to many relationship






/** I am the owner**/
    @OneToMany(cascade={CascadeType.ALL})
    @JoinColumn(name="DepartmentID", nullable = false)
    List<Employees> employees;


1. Why we used nullable = false ??  Well, we will remove that as follow and run our test.java once again.


/** I am the owner**/
    @OneToMany(cascade={CascadeType.ALL})
    @JoinColumn(name="DepartmentID")
    List<Employees> employees;


Now, hibernate will throw an error as follows:
Hibernate: insert into department (DepartName) values (?)
Hibernate: insert into employees (firstName, lastName) values (?, ?)
Aug 4, 2012 11:18:14 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 1364, SQLState: HY000
Aug 4, 2012 11:18:14 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Field 'DepartmentID' doesn't have a default value
Exception in thread "main" org.hibernate.exception.GenericJDBCException: Field 'DepartmentID' doesn't have a default value
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)


This is because we have defined as not null column in employee table for the column departmentID.
Now just for testing, let us make employee.department column as null and will remove the entire joincolumn annotation itself as follows


/** I am the owner**/
    @OneToMany(cascade={CascadeType.ALL})
     List<Employees> employees;


Now we run the test.java, you will see some different error as follows


Aug 4, 2012 11:21:55 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 1146, SQLState: 42S02
Aug 4, 2012 11:21:55 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Table 'sampledb.department_employees' doesn't exist
Exception in thread "main" org.hibernate.exception.SQLGrammarException: Table 'sampledb.department_employees' doesn't exist


Well, this is tricky, hibernate looking for the third table to make the relationship between department and employee. In the database model, in order to make one to many relationship, either we can have the third table or we can define the foreign key in the child table that refers to master.


Rough scheme


Department (ID Primary Key, Name varchar(100)
Employee(ID Primary Key, FirstName Varchar(100)
Department_Employee(Department_ID foreign key to department, Employee_ID foreign key to Employee)


But in our example, we are using the foreign key concept without the third table for mapping between department and employee. So let us roll back all our changes and will continue from there.


Rollback in the department.java as follows


/** I am the owner**/
    @OneToMany(cascade={CascadeType.ALL})
    @JoinColumn(name="DepartmentID", nullable = false)
    List<Employees> employees;


And also, make departmentid in the employee table as not null.


And also,


What does CascadeType.ALL do?


CascadeType.PERSIST: cascades the persist (create) operation to associated entities persist() is called or if the entity is managed
CascadeType.MERGE: cascades the merge operation to associated entities if merge() is called or if the entity is managed
CascadeType.REMOVE: cascades the remove operation to associated entities if delete() is called
CascadeType.REFRESH: cascades the refresh operation to associated entities if refresh() is called
CascadeType.DETACH: cascades the detach operation to associated entities if detach() is called
CascadeType.ALL: all of the above


Now again let us run the test.java.  You can see the sql query as follows


Hibernate: insert into department (DepartName) values (?)
Hibernate: insert into employees (firstName, lastName, DepartmentID) values (?, ?, ?)
Hibernate: insert into employees (firstName, lastName, DepartmentID) values (?, ?, ?)
Hibernate: update employees set DepartmentID=? where ID=?
Hibernate: update employees set DepartmentID=? where ID=?


If you observe carefully, hibernate using the extra update statement to update the child with the parent table key. We can also optimize this by changing in the department.java as follows


/** I am the owner**/
@OneToMany(cascade={CascadeType.ALL})
@JoinColumn(name="DepartmentID", updatable = false,  nullable = false)
List<Employees> employees;


Now let us run test.java again. Now you can see the query as follows


Hibernate: insert into department (DepartName) values (?)
Hibernate: insert into employees (firstName, lastName, DepartmentID) values (?, ?, ?)
Hibernate: insert into employees (firstName, lastName, DepartmentID) values (?, ?, ?)


 


Now let us move further updating master, deleting master, update child, etc


Just in the mysql, do the following


TRUNCATE department
TRUNCATE employees


Now let us update only master. Change the test.java as follows and we will run one by one.




package test;

import java.util.ArrayList;
import java.util.List;
import org.hibernate.Session;
import domain.*;
import HibernateUtilities.*;

public class Test {
public static void main(String[] args) {
addNewMasterAndDetail();
//updateOnlyMaster();
//updateonlyDetail();
//deleteOnlyDetail();
//deleteMaster();
}

public static void addNewMasterAndDetail()
{
// Now let us create Department
Department d1 = new Department();
d1.setDepartName("Accounts");

// Now let us some employees
List<Employees> empList = new ArrayList<Employees>();
Employees e1 = new Employees();

e1.setFirstName("John");
e1.setFirstName("Mike");
e1.setDepartment(d1);
empList.add(e1);

e1 = new Employees();
e1.setFirstName("Smith");
e1.setFirstName("Robert");
e1.setDepartment(d1);
empList.add(e1);

d1.setEmployees(empList);

Session session = HibernateUtil.beginTransaction();
session.save(d1);
HibernateUtil.CommitTransaction();

}

public static void updateOnlyMaster()
{
//Now Let us update the master alone i.e Department
Session session = HibernateUtil.beginTransaction();
Department d2 = (Department) session.createQuery("from Department where id = 1").uniqueResult();
d2.setDepartName("Accounts Modified");
session.save(d2);
HibernateUtil.CommitTransaction();
}


public static void updateonlyDetail()
{
//Now Let us update the detail alone i.e employee
Session session = HibernateUtil.beginTransaction();
Department d2 = (Department) session.createQuery("from Department where id = 1").uniqueResult();
d2.getEmployees().get(0).setFirstName("changed first name");
session.save(d2);
HibernateUtil.CommitTransaction();
}

public static void deleteOnlyDetail()
{
//Now Let us update the master alone i.e Department
Session session = HibernateUtil.beginTransaction();
Department d2 = (Department) session.createQuery("from Department where id = 2").uniqueResult();
d2.getEmployees().clear();
session.saveOrUpdate(d2);
HibernateUtil.CommitTransaction();
}

public static void deleteMaster()
{
//Now Let us update the master alone i.e Department
Session session = HibernateUtil.beginTransaction();
Department d2 = (Department) session.createQuery("from Department where id = 1").uniqueResult();
session.delete(d2);
HibernateUtil.CommitTransaction();
}


}



1. Now Run the test.java and observer the sql output as follows

Hibernate: insert into department (DepartName) values (?)
Hibernate: insert into employees (firstName, lastName, DepartmentID) values (?, ?, ?)
Hibernate: insert into employees (firstName, lastName, DepartmentID) values (?, ?, ?)


2. Now in the test.java, comment the first method and uncomment the second method as follows


public static void main(String[] args) {
        //addNewMasterAndDetail();
        updateOnlyMaster();
        //updateonlyDetail();
        //deleteOnlyDetail();
        //deleteMaster();
    }


  SQL Output as follows:
Hibernate: select department0_.ID as ID0_, department0_.DepartName as DepartName0_ from department department0_ where department0_.ID=1
Hibernate: update department set DepartName=? where ID=?

3. Now in the test.java, comment all the method and uncomment updateonlyDetail and run test.java.

Hibernate: select department0_.ID as ID0_, department0_.DepartName as DepartName0_ from department department0_ where department0_.ID=1
Hibernate: select employees0_.DepartmentID as Departme4_0_1_, employees0_.ID as ID1_, employees0_.ID as ID1_0_, employees0_.DepartmentID as Departme4_1_0_, employees0_.firstName as firstName1_0_, employees0_.lastName as lastName1_0_ from employees employees0_ where employees0_.DepartmentID=?
Hibernate: update employees set firstName=?, lastName=? where ID=?


3. Now in the test.java, comment all the method and uncomment deleteOnlyDetail and run test.java. Here is the sql output

Hibernate: select department0_.ID as ID0_, department0_.DepartName as DepartName0_ from department department0_ where department0_.ID=1
Hibernate: select employees0_.DepartmentID as Departme4_0_1_, employees0_.ID as ID1_, employees0_.ID as ID1_0_, employees0_.DepartmentID as Departme4_1_0_, employees0_.firstName as firstName1_0_, employees0_.lastName as lastName1_0_ from employees employees0_ where employees0_.DepartmentID=?

Here is a problem, hibernate actually not deleting the detail. So we need to do something


orphanRemoval is an entirely ORM-specific thing. It marks "child" entity to be removed when it's no longer referenced from the "parent" entity, e.g. when you remove the child entity from the corresponding collection of the parent entity.

So let us change our department.java as follows

/** I am the owner**/
@OneToMany(cascade={CascadeType.ALL},  orphanRemoval=true)
@JoinColumn(name="DepartmentID", updatable = false,  nullable = false)
List<Employees> employees


Now again run test.java, you can see the query output as follows

Hibernate: select department0_.ID as ID0_, department0_.DepartName as DepartName0_ from department department0_ where department0_.ID=1
Hibernate: select employees0_.DepartmentID as Departme4_0_1_, employees0_.ID as ID1_, employees0_.ID as ID1_0_, employees0_.DepartmentID as Departme4_1_0_, employees0_.firstName as firstName1_0_, employees0_.lastName as lastName1_0_ from employees employees0_ where employees0_.DepartmentID=?
Hibernate: delete from employees where ID=?
Hibernate: delete from employees where ID=?


3. Finally, we will delete the master and then it will delete the detail too.
Hibernate: select department0_.ID as ID0_, department0_.DepartName as DepartName0_ from department department0_ where department0_.ID=1
Hibernate: select employees0_.DepartmentID as Departme4_0_1_, employees0_.ID as ID1_, employees0_.ID as ID1_0_, employees0_.DepartmentID as Departme4_1_0_, employees0_.firstName as firstName1_0_, employees0_.lastName as lastName1_0_ from employees employees0_ where employees0_.DepartmentID=?
Hibernate: delete from employees where ID=?
Hibernate: delete from employees where ID=?
Hibernate: delete from department where ID=?


 


That’s all.


Read More
Posted in Hibernate Mapping | No comments

Thursday, 2 August 2012

One to many mapping using bidirectional relationship– ManytoOne as owner

Posted on 11:36 by Unknown

First let is look the hibernate documentation on this as follows

One to many association is annotated by @OneToMany(mappedBy=...).    Here is the documentation link

@Entity
public class Troop {
@OneToMany(mappedBy="troop")
public Set<Soldier> getSoldiers() {
...
}

@Entity
public class Soldier {
@ManyToOne
@JoinColumn(name="troop_fk")
public Troop getTroop() {
...
}


Troop has a bidirectional one to many relationship with Soldier through the troop property. You don't have to (must not) define any physical mapping in the mappedBy side.


In bi-directional mapping, the parent table can be retrieved by the child table and the child table can be retrieved by the parent table. Means retrieval can be done in both direction or bi-directional. That's why we call it bi-directional mapping.


Some examples


There are two table WRITER and STORY. One writer can write multiple stories. So the relation is one-to-many . Using bi-directional relation, From WRITER object you can get bag of Stories and from story object you can get writer object.


Now let us goto our example.


In this example, we will see many to one as owning side i.e on the detail side.  As per this example,
department is not the owner, where as employee is the owner.


Step : 1
In mysql , create the table as shown
image


Step : 2


Let us set the environment. Follow this post to set up Hibernate with java in eclipse IDE.


Step : 3


Let us create Beans as follows


package domain;


import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.OneToMany;
@Entity
@Table(name = "department")
public class Department {

@Id
@GeneratedValue
@Column(name = "ID")
private int ID;

@Column(name = "DepartName")
private String departName;


/**
mappedBy – means “I am not the owner side”, I am mapped by Employee from the other side of the relationship.
It will also not create the database column which makes sense, I would expect a foreign key on the Employee table instead.
Here we have used department as mapped by, so there must be property on the Employee Class.

Department has a bidirectional one to many relationship with Employee through the department property.
You don't have to (must not) define any physical mapping in the mappedBy side.

orphanRemoval=true is used because, even though we specified cascadetype all, but if only child records are deleted,
then when you save the master, the child will not delete. for this, we have used orphanRemoval=true.

**/

@OneToMany(fetch=FetchType.EAGER, cascade = CascadeType.ALL, mappedBy="department", orphanRemoval=true)
List<Employees> employees;

public int getID() {
return ID;
}

public void setID(int iD) {
ID = iD;
}

public String getDepartName() {
return departName;
}

public void setDepartName(String departName) {
this.departName = departName;
}

public List<Employees> getEmployees() {
return employees;
}

public void setEmployees(List<Employees> employees) {
this.employees = employees;
}



}

Employees



 

package domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.ManyToOne;
import javax.persistence.JoinColumn;


@Entity
@Table(name = "employees")
public class Employees {

@Id
@GeneratedValue
private int ID;
@Column(name = "firstName")
private String firstName;

@Column(name = "lastName")
private String lastName;

@ManyToOne
@JoinColumn(name="DepartmentID")
private Department department;

public int getID() {
return ID;
}

public void setID(int iD) {
ID = iD;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public Department getDepartment() {
return department;
}

public void setDepartment(Department department) {
this.department = department;
}

}


hibernate.cfg.xml


<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/sampledb</property>
<property name="connection.username">root</property>
<property name="connection.password">123</property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>

<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>



<!-- Mapping Classes -->
<mapping class="domain.Department" />
<mapping class="domain.Employees" />

</session-factory>
</hibernate-configuration>

Test Class

package test;

import java.util.ArrayList;
import java.util.List;
import org.hibernate.Session;
import domain.*;
import HibernateUtilities.*;

public class Test {

public static void main(String[] args) {

addNewMasterAndDetail();
//updateOnlyMaster();
//deleteMaster();
//updateonlyDetail();
//deleteOnlyDetail();

}

public static void addNewMasterAndDetail()
{
// Now let us create Department
Department d1 = new Department();
d1.setDepartName("Accounts");

// Now let us some employees
List<Employees> empList = new ArrayList<Employees>();
Employees e1 = new Employees();

e1.setFirstName("John");
e1.setFirstName("Mike");
e1.setDepartment(d1);
empList.add(e1);

e1 = new Employees();
e1.setFirstName("Smith");
e1.setFirstName("Robert");
e1.setDepartment(d1);
empList.add(e1);

d1.setEmployees(empList);

Session session = HibernateUtil.beginTransaction();
session.save(d1);
HibernateUtil.CommitTransaction();

}

public static void updateOnlyMaster()
{
//Now Let us update the master alone i.e Department
Session session = HibernateUtil.beginTransaction();
Department d2 = (Department) session.createQuery("from Department where id = 1").uniqueResult();
d2.setDepartName("Accounts Modified");
session.save(d2);
HibernateUtil.CommitTransaction();
}

public static void deleteMaster()
{
//Now Let us update the master alone i.e Department
Session session = HibernateUtil.beginTransaction();
Department d2 = (Department) session.createQuery("from Department where id = 1").uniqueResult();
session.delete(d2);
HibernateUtil.CommitTransaction();
}

public static void updateonlyDetail()
{
//Now Let us update the master alone i.e Department
Session session = HibernateUtil.beginTransaction();
Department d2 = (Department) session.createQuery("from Department where id = 2").uniqueResult();
d2.getEmployees().get(0).setFirstName("changed first name");
session.save(d2);
HibernateUtil.CommitTransaction();
}

public static void deleteOnlyDetail()
{
//Now Let us update the master alone i.e Department
Session session = HibernateUtil.beginTransaction();
Department d2 = (Department) session.createQuery("from Department where id = 2").uniqueResult();
d2.getEmployees().clear();
session.saveOrUpdate(d2);
HibernateUtil.CommitTransaction();
}
}


Now you can run test.java as java application.


Project Structure.


image


 


 




 


 



 

 

 



 



 



 

 
Read More
Posted in Hibernate Mapping | No comments

Wednesday, 1 August 2012

Hibernate Mapping one to Many–Some useful explanation from the internet

Posted on 10:06 by Unknown

Example 1-59 @OneToMany - Customer Class With Generics

@Entity
public class Customer implements Serializable {
    ...
    @OneToMany(cascade=ALL, mappedBy="customer")
    public Set<Order> getOrders() {
        return orders;
    }
    ...
}

Example 1-60 @ManyToOne - Order Class With Generics

@Entity
public class Order implements Serializable {
    ...
    @ManyToOne
    @JoinColumn(name="CUST_ID", nullable=false)
    public Customer getCustomer() {
        return customer;
    }
    ...
}

To understand this, you must take a step back. In OO, the customer owns the orders (orders are a list in the customer object). There can't be an order without a customer. So the customer seems to be the owner of the orders.

But in the SQL world, one item will actually contain a pointer to the other. Since there is 1 customer for N orders, each order contains a foreign key to the customer it belongs to. This is the "connection" and this means the order "owns" (or literally contains) the connection (information). This is exactly the opposite from the OO/model world.

This may help to understand:

public class Customer {
     // This field doesn't exist in the database
     // It is simulated with a SQL query
     // "OO speak": Customer owns the orders
     private List<Order> orders;
}

public class Order {
     // This field actually exists in the DB
     // In a purely OO model, we could omit it
     // "DB speak": Order contains a foreign key to customer
     private Customer customer;
}

The inverse side is the OO "owner" of the object, in this case the customer. The customer has no columns in the table to store the orders, so you must tell it where in the order table it can save this data (which happens via mappedBy).

The entity which has the table with foreign key in the database in owning entity and other side is inverse entity

*******************************************************************************************************************************************

Assume that we have 2 tables, ENQUIRY and ELEMENT with a One-to-Many relationship such that an Enquiry has many Elements. And if we want to enforce the NOT NULL constraint on foreign key column ELEMENT.ENQUIRY_ID. This relationship looks like so when modeling the Enquiry object with Hibernate:

@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "ENQUIRY_ID", referencedColumnName = "ID")
private Set elements = new HashSet();

When you enforced the NOT NULL constraint at the database level you will received the following error

Caused by: java.sql.BatchUpdateException: ORA-01400: cannot insert NULL into ("ELEMENT"."ENQUIRY_ID")

So Hibernate is obviously persisting the collection of elements before the parent enquiry and then going back and doing an UPDATE on the foreign key field afterwards (so INSERT collection items with NULL foreign key, INSERT parent, UPDATE collection item foreign keys) as it doesn’t realise the foreign key column will always be non-null.

We must explicitly tell Hibernate that the foreign key column is NOT NULL. It can then persist the parent enquiry first followed by the collection items. To do this, add the following clause to the @JoinColumn annotation:

@JoinColumn(name = "ENQUIRY_ID", referencedColumnName = "ID", nullable = false)

This way, not only are you ensuring database best-practice, but Hibernate will also have to issue less statements (so INSERT parent, INSERT collection items) which should be a more efficient transaction statement.

*******************************************************************************************************************************************

Bidirectional One-To-Many
Let us create a Bidirectional One-To-Many relationship between Question and Choice, a Question has many choices.


  1. Setup entities

    @Entity
    @Table (name = "QUESTION")
    public class Question implements Serializable
    {

    @Id
    @GeneratedValue (strategy = GenerationType.AUTO)
    @Column (name = “QUESTION_ID”)
    private Long id;

    @Column (name = “TEXT”)
    private String text;
    ……………


    @Entity
    @Table (name = "CHOICE")
    public class Choice implements Serializable
    {

    @Id
    @GeneratedValue (strategy = GenerationType.AUTO)
    @Column (name = “CHOICE_ID”)
    private Long id;

    @Column (name = “TEXT”)
    private String text;
    ……………


  2. Setup the ONE side on Question – I read ONE Question has MANY CHOICE(S).
    Question

    @OneToMany (mappedBy="question")
    private Set choices = new HashSet();

    mappedBy – means “I am not the owner side”, I am mapped by question from the other side of the relationship. It will also not create the database column which makes sense, I would expect a foreign key on the CHOICE table instead.


  3. Setup the Many side on Choice – I read on Choice.java MANY Choice has ONE Question
    @ManyToOne
    @JoinColumn (name="QUESTION_ID")
    private Question question;

    the @JoinColumn indicate the owning side of the relationship, it is responsible for updating the database column. It will create the QUESTION_ID column on the CHOICE table


  4. Reversing the Relationship so that the owning side is the Question instead
    Question

    @OneToMany
    @JoinColumn (name = "QUESTION_ID")
    private Set choices = new HashSet();

    Choice

    @ManyToOne
    @JoinColumn (name="QUESTION_ID", updatable = false, insertable = false)
    private Question question;


  5. Finally we need to use a List instead of Set – so we can preserve the order of the Choice(s).Question

    @OneToMany (
    cascade = {CascadeType.ALL},
    fetch = FetchType.EAGER
    )
    @JoinColumn (name = "QUESTION_ID")
    @org.hibernate.annotations.Cascade(
    value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN
    )
    @org.hibernate.annotations.IndexColumn(name = "CHOICE_POSITION")
    private List choices = new ArrayList();

    Choice

    @ManyToOne
    @JoinColumn (name="QUESTION_ID", nullable = false, updatable = false, insertable = false)
    private Question question;

    the @org.hibernate.annotations.IndexColumn defines the colum CHOICE_POSITION that will be used to maintain the order of the list. Some how reversing the ownership is the only way to get the IndexColumn to work



*******************************************************************************************************************************************

Read More
Posted in Hibernate Mapping | No comments
Older Posts Home
Subscribe to: Posts (Atom)

Popular Posts

  • ZK Example for inline Editing with Add New and Delete
    I am quite impressed on this demo from ZK . But adding new record and delete existing record is missing as part of typical CRUD. So i thoug...
  • Hibernate Validator Example 2
    In this example, we will see some more validation constraints such as @email, @past, @length, etc. And also we will also define custom error...
  • ZK Passing Parameter between two files using MVVM–Part 1
    Overview This is the first series of articles about Passing parameter between two zul files using MVVM Design pattern .This article will fo...
  • ViewModel Class Java Annotation @Init, @NotifyChange, @Command
    In following sections we'll list all syntaxes that can be used in implementing a ViewModel and applying ZK bind annotation. The ZK binde...
  • Good Website Design Links
    Form Design Label Placement in Forms International Address Fields in Web Forms 40 Eye-Catching Registration Pages blog-comment-form-...
  • ZK Border Layout–Another example
    This examples show how you can use ZK Border Layout to show the product information on clicking image. ZK Version 6 Project Name : BorderL...
  • History of Present Illness
    HPI - One of the main component of Clinical History. What is an HPI ? The history of present illness (HPI) is a chronological description...
  • ZK MVVM Form Binding CRUD with Spring and Hibernate - Part 4
    Presentation Layer using ZK Framework          In part 3 , We have completed Spring integration with hibernate. In this post, we will des...
  • How to refer CSS File in ZK Style tag
    In this example, we will see how to create CSS file as separate file and include in zul file to change the look and feel Project structure a...
  • MVVM Modal window–Pass Parameter and Return values
    In this post, we will see how we can pass some values to the modal window when calling from the parent window and also vice versa (i.e) retu...

Categories

  • Billing Process
  • C Workbook
  • C++ Workbook
  • Eclipse Tips
  • EDI 5010
  • EMR Appointment Features
  • EMR Labs Stuff
  • EMR PMS Links
  • EMR Use cases
  • EMR Vital Sign
  • Good Website Design
  • Hibernate Criteria Queries
  • Hibernate Introduction
  • Hibernate Introduction Setup
  • Hibernate Mapping
  • Hibernate POC
  • Hibernate Validator
  • Hibernate–Java Environment setup
  • HPI
  • Java
  • Maven
  • MU Certification
  • NPI
  • PQRS
  • Practice Management System
  • Spring Security
  • Tech Links
  • Today Tech Stuff
  • zk
  • ZK Hibernate
  • ZK 5 Databinding
  • ZK Application
  • ZK Calling Another ZUL
  • ZK CheckBox
  • ZK CreateComponents
  • ZK CSS
  • ZK extended Components
  • ZK Foreach
  • ZK Forum Posts
  • ZK Framework
  • ZK Hibernate Setup
  • ZK ID Space
  • ZK Include
  • ZK Installation
  • ZK iReport
  • ZK Layout
  • ZK Listitem Pagination
  • ZK Message Box
  • ZK MVC
  • ZK MVC Combox Box
  • ZK MVC CRUD Examples
  • ZK MVC Listbox
  • ZK MVVM
  • ZK MVVM Combo
  • ZK MVVM CRUD
  • ZK MVVM ListBox
  • ZK Spring
  • ZK TextBox

Blog Archive

  • ▼  2013 (105)
    • ▼  December (3)
      • EDI Instructions
      • Understanding EDI Structure
      • What is an EDI ?
    • ►  September (7)
    • ►  August (13)
    • ►  July (1)
    • ►  June (11)
    • ►  May (3)
    • ►  April (14)
    • ►  March (19)
    • ►  February (21)
    • ►  January (13)
  • ►  2012 (177)
    • ►  December (1)
    • ►  November (13)
    • ►  October (19)
    • ►  September (24)
    • ►  August (26)
    • ►  July (6)
    • ►  June (37)
    • ►  May (30)
    • ►  April (16)
    • ►  March (1)
    • ►  January (4)
  • ►  2011 (5)
    • ►  December (1)
    • ►  November (1)
    • ►  July (1)
    • ►  June (1)
    • ►  April (1)
  • ►  2010 (1)
    • ►  September (1)
Powered by Blogger.

About Me

Unknown
View my complete profile