Posts filed under 'Java, J2EE'

JPA persistance best practices and orm configuration….Tomcat configuration tips

The issues of persistance have taken the most of my sparetime recently as I have planned the implementation details of JPA entity layer…
good basis for investigation have provided the 2 series of peristance provided by IBM Developerworrks articles..namely

Patterns of persistence, Part 1: Strategies and best practices for modern ORM tools

and Patterns of persistence, Part 2: Increase code reuse and enhance performance,other useful links are oracle’s best basic Java
Persistance API practices
article and the JEE blueprints of persistance….

 as recommeded in the basic Java Percstance API practices the Integration with Spring is fabulous combination ….in addition if you utilize hibernate enity interceptors as was the case in IBM persistance series the configuratio with spring is done in the folllowng way http://forum.springframework.org/archive/index.php/t-10512.html  and voila you get the benefit of the auditing features of JPA enity modifications and updates…

Enabling compression on the web server will make data be transferred in compressed form. The browser will decompress the data on the fly, making the application faster. If your application uses Ajax, what usually increases the volume of data transferred from server to client, compression of data will significantly improve your application performance.

Here is how to enable GZIP compression on Tomcat: edit file /conf/server.xml and add to the HTTP Connector configuration something like this:

 

10 tomcat configurataion tips

Add comment June 24th, 2008

new enchancments to EJB 3 in the form of Singleton pattern

The article about the futher enhancments in EJB 3 specific spectrum by Reha Rahman highlits the new dimensions the EJB 3 specification is heading…added pattern of Singletons…you could send your feedback about the planned new features of EJB 3.1…give your feedback….also big influence in the whole was the Oracle’s Bea aqusition…the the Spring supporters are now one mammunt….read more about Rod Jhonsson’s feelings about this merge. Planning to attend some major Java seminars in Europe…why not to attend Java Sympohisum held In Prague during next Summer -

 

Add comment January 26th, 2008

open source JEE Application server/web server comparision

hi,

just brief overview of the different features common for open source JEE application servers

jboss,geronimo and Tomcat  on JavaWorld article - Jboss,Geronimo or Tomcat ?

I just found out that Red Hat provides Jboss Developer Studio for 99 $ ..is it worth the investment…well give it a try and …..give feedback…

Add comment December 11th, 2007

JPA article in Serverside

The September 2007 Techcal article about data modelling with JPA, defining your Object Model with JPA

by Cris Maki highlights also the benefits of using JPA. For my self the article provided valuable information of how to implement JPA entity super class with @MappedSuperclass-annotation.

In addition, @EntityListeners({ModelListener.class})

EntityLisner-annotation helps to implement Listener class for entity lifesycles..ie when the enity is persited and merged …so this lisner class is then handy to have.

Add comment September 27th, 2007

Red Hat Developer Suite released….attend free seminar

Hi,

The season is ready for other useful tools for giving ultimate gains for developer to utilize them…one of these IDE’s spectrum is Red Hat Developer Suite released by Ret Hat. The tooling helps you to benefit from the usage os Seams

framework. Attend free SOA seminar provided by Red Hat held at Innopoli 2 on 18th of October…attend now and hear more what Red Hat SOA has to offer for Java Developers ….the seminar info in Finnish

Tule kuulemaan ja näkemään miten SOA maailma muuttaa toimintojasi ja tekee elämästäsi helpommin hallittavaa. Tämä ilmainen SOA seminaari pidetään tiistaina 16. lokakuuta klo 12.00 osoitteessa: Technopolis Innopoli, Tekniikantie 12, 02150 Espoo.

12:00 Ilmoittautuminen & kahvi
12:15 Tilaisuuden avaus (Moonsoft/Nordicmind)
12:20 Simple, Open & Affordable (Petri Maanonen, Red Hat)

  • JBoss - mikä se on?
  • Yhdistymällä teknologiaetua SOAan
13:00 JBoss-komponentit (Petri Maanonen, Red Hat)

  • Muutokset Jboss-perheessä
  • JBoss Enterprise Platform ja tukitasot
  • Application Stack
13:45 Kahvitauko
14:00 Tuki kehitysympäristöihin ja tuotantoon (Thomas Qvarnström, Red Hat)

  • Mitä kehittäjä hyötyy?
  • Tuotannon kriittisyys?
  • Developer Subscribtion ja Developer Studio
15:00 Demo (Thomas Qvarnström, Red Hat)

  • Hallinta ja ylläpidettävyys
  • Kehityspuolelta tuotantoon?
16:00 Q&A

Add comment September 24th, 2007

JPA and Spring Sample Application

Hi,

As I started to play with the Spring 2.0 and JPA technologies I came up with a simplistic data models and samples of how to create Entities using Hibernate EntityManager in the background and how to access them with Spring DAO classes implementing JpaTemplate way of handling with the EntityManager. In addition, a AbstractJpaTest class was created to peform Junit test againts Spring DAO layer classes.

Database initialization sql script:
drop table Contract;
drop table ContractPerson;
drop table Company;
drop table Adress;

drop index ContractHost;
drop index ContractQuest;
drop index ContractAdress;
drop SEQUENCE adress_seq;
drop SEQUENCE company_seq;
drop SEQUENCE contractperson_seq;
drop SEQUENCE contract_seq;

drop table Contract;
drop table ContractPerson;
drop table Company;
drop table Adress;

CREATE SEQUENCE adress_seq START 1000;
CREATE SEQUENCE company_seq START 1000;
CREATE SEQUENCE contractperson_seq START 1000;
CREATE SEQUENCE contract_seq START 1000;

create table Adress (
Adress_id int not null DEFAULT NEXTVAL(’adress_seq’),
status varchar(2) null,
addr1 varchar(80) not null,
addr2 varchar(40) null,
city varchar(80) not null,
state varchar(80) not null,
zip varchar(20) not null,
country varchar(20) not null,
phone varchar(80) not null,
constraint pk_adress primary key (Adress_id)
);
create table Company (
Company_id int not null DEFAULT NEXTVAL(’company_seq’),
company_adress_id int not null,
name varchar(40) not null,
constraint pk_company primary key (Company_id),
constraint fk_company_adress foreign key (company_adress_id ) references Adress (Adress_id)
);
create table ContractPerson
(
ContractPerson_id int not null DEFAULT NEXTVAL(’contractperson_seq’),
person_address_id int not null,
company_id int not null,
email varchar(80) not null,
firstname varchar(80) not null,
lastname varchar(80) not null,
pincode varchar(15) not null,
constraint pk_contractperson primary key (ContractPerson_id) ,
constraint fk_adress foreign key (person_address_id) references Adress (Adress_id),
constraint fk_company_id foreign key (company_id) references Company (Company_id)
);
create table Contract (
contract_id int not null DEFAULT NEXTVAL(’contract_seq’),
host_persion_id int not null,
quest_persion_id int not null,
contract_adress_id int not null,
status varchar(2) not null,
created_date date not null,
document1_name varchar(50) null,
document2_name varchar(50) null,
document1_path varchar(50) null,
document2_path varchar(50) null,

constraint pk_contract primary key (contract_id) ,
constraint fk_host_person foreign key (host_persion_id) references ContractPerson (ContractPerson_id),
constraint fk_quest_person foreign key (quest_persion_id) references ContractPerson (ContractPerson_id),
constraint fk_contract_adress foreign key (contract_adress_id) references Adress (Adress_id)
);
create index ContractHost on Contract (host_persion_id );
create index ContractQuest on Contract (quest_persion_id );
create index ContractAdress on Contract (contract_adress_id );

ALTER TABLE adress OWNER TO user;
GRANT ALL ON TABLE adress TO user;
GRANT ALL ON TABLE adress TO contactdb;

ALTER TABLE company OWNER TO user;
GRANT ALL ON TABLE company TO user;
GRANT ALL ON TABLE company TO contact;

ALTER TABLE contract OWNER TO user;
GRANT ALL ON TABLE contract TO user;
GRANT ALL ON TABLE contract TO contact;

ALTER TABLE contractperson OWNER TO user;
GRANT ALL ON TABLE contractperson TO contact;
GRANT ALL ON TABLE contractperson TO user;

ALTER TABLE adress_seq OWNER TO user;
GRANT ALL ON TABLE adress_seq TO contact;
GRANT ALL ON TABLE adress_seq TO user;

ALTER TABLE company_seq OWNER TO user;
GRANT ALL ON TABLE company_seq TO contact;
GRANT ALL ON TABLE company_seq TO user;

ALTER TABLE contract_seq OWNER TO user;
GRANT ALL ON TABLE contract_seq TO contact;
GRANT ALL ON TABLE contract_seq TO user;

ALTER TABLE contractperson_seq OWNER TO user;
GRANT ALL ON TABLE contractperson_seq TO contact;
GRANT ALL ON TABLE contractperson_seq TO user;

commit;

Beans configuration file:

Wieard issue that I’m not able to paste spring beans configuration file context.
Adress Entity:

package fi.passiba.contractdb.persistence;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.SequenceGenerator;
import javax.persistence.Id;

@Entity
public class Adress implements Serializable {
@Id
@Column(name=”adress_id”)
@GeneratedValue (strategy = GenerationType.SEQUENCE)
@SequenceGenerator(name=”USER_SEQUENCE_GENERATOR_ADDRESS”,sequenceName=”adress_seq”)

private int adressId;

@Column(name=”country”)
private String country;

@Column(name=”state”)
private String state;

@Column(name=”status”)
private String status;

@Column(name=”zip”)
private String zip;

@Column(name=”phone”)
private String phone;

@Column(name=”addr2″)
private String addr2;

@Column(name=”addr1″)
private String addr1;

@Column(name=”city”)
private String city;

private static final long serialVersionUID = 1L;

public Adress() {
super();
}

public int getAdressId() {
return this.adressId;
}

public String getCountry() {
return this.country;
}

public void setCountry(String country) {
this.country = country;
}

public String getState() {
return this.state;
}

public void setState(String state) {
this.state = state;
}

public String getStatus() {
return this.status;
}

public void setStatus(String status) {
this.status = status;
}

public String getZip() {
return this.zip;
}

public void setZip(String zip) {
this.zip = zip;
}

public String getPhone() {
return this.phone;
}

public void setPhone(String phone) {
this.phone = phone;
}

public String getAddr2() {
return this.addr2;
}

public void setAddr2(String addr2) {
this.addr2 = addr2;
}

public String getAddr1() {
return this.addr1;
}

public void setAddr1(String addr1) {
this.addr1 = addr1;
}

public String getCity() {
return this.city;
}

public void setCity(String city) {
this.city = city;
}

}

Company Entity:
package fi.passiba.contractdb.persistence;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;

@Entity
public class Company implements Serializable {
@Id
@Column(name=”company_id”)
@GeneratedValue (strategy = GenerationType.SEQUENCE)
@SequenceGenerator(name=”USER_SEQUENCE_GENERATOR_COMPANY”,sequenceName=”company_seq”)

private int companyId;

@Column(name=”name”)
private String name;

@OneToOne(cascade = CascadeType.ALL, fetch=FetchType.LAZY)
@JoinColumn(name = “company_adress_id”, referencedColumnName = “Adress_id”)
private Adress address_id;

private static final long serialVersionUID = 1L;

public Company() {
super();
}

public int getCompanyId() {
return this.companyId;
}

public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}

public Adress getAdress() {
return this.address_id;
}

public Adress setAdress(Adress adress) {
return this.address_id = adress;
}

}

Contract Entity:

package fi.passiba.contractdb.persistence;

import java.io.Serializable;
import java.sql.Timestamp;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;

@Entity
@NamedQueries( {
@NamedQuery(name = “Contract.findContractByDocument1Name”, query = “SELECT c FROM Contract AS c WHERE c.document1Name LIKE ?1″),
@NamedQuery(name = “Contract.findContractByDocument2Name”, query = “SELECT c FROM Contract AS c WHERE c.document2Name LIKE ?1″),
@NamedQuery(name = “Contract.findContractByQuest”, query = “SELECT c FROM Contract AS c JOIN c.questPersionId AS p WHERE p.lastname = ?1″),
@NamedQuery(name = “Contract.findContractByHost”, query = “SELECT c FROM Contract AS c JOIN c.hostPersionId AS p WHERE p.lastname = ?1″),
@NamedQuery(name = “Contract.findContractByStatus”, query = “SELECT c FROM Contract AS c WHERE c.status = ?1″),
@NamedQuery(name = “Contract.findContractByDate”, query = “SELECT c FROM Contract AS c WHERE c.createdDate > :currentDate”)

}
)
public class Contract implements Serializable {
@Id
@Column(name=”contract_id”)
@GeneratedValue (strategy = GenerationType.SEQUENCE)
@SequenceGenerator(name=”USER_SEQUENCE_GENERATOR_CONTRACT”,sequenceName=”contract_seq”)

private int contractId;

@Column(name=”status”)
private String status;

@Column(name=”document2_name”)
private String document2Name;

@Column(name=”document2_path”)
private String document2Path;

@Column(name=”document1_name”)
private String document1Name;

@Column(name=”document1_path”)
private String document1Path;

@Column(name = “created_date”)
private Timestamp createdDate;

@OneToOne(cascade = CascadeType.ALL, fetch=FetchType.LAZY)
@JoinColumn(name = “host_persion_id”, referencedColumnName = “ContractPerson_id”)
private Contractperson hostPersionId;

@OneToOne(cascade = CascadeType.ALL , fetch=FetchType.LAZY)
@JoinColumn(name = “quest_persion_id”, referencedColumnName = “ContractPerson_id”)
private Contractperson questPersionId;

@OneToOne(cascade = CascadeType.ALL, fetch=FetchType.LAZY)
@JoinColumn(name = “contract_adress_id”, referencedColumnName = “Adress_id”)
private Adress contract_address_id;

private static final long serialVersionUID = 1L;

public Contract() {
super();
}

public int getContractId() {
return this.contractId;
}

public String getStatus() {
return this.status;
}

public void setStatus(String status) {
this.status = status;
}

public String getDocument2Name() {
return this.document2Name;
}

public void setDocument2Name(String document2Name) {
this.document2Name = document2Name;
}

public String getDocument2Path() {
return this.document2Path;
}

public void setDocument2Path(String document2Path) {
this.document2Path = document2Path;
}

public String getDocument1Name() {
return this.document1Name;
}

public void setDocument1Name(String document1Name) {
this.document1Name = document1Name;
}

public String getDocument1Path() {
return this.document1Path;
}

public void setDocument1Path(String document1Path) {
this.document1Path = document1Path;
}

public Contractperson getHostPersionId() {
return this.hostPersionId;
}

public void setHostPersionId(Contractperson hostPersionId) {
this.hostPersionId = hostPersionId;
}

public Contractperson getQuestPersionId() {
return this.questPersionId;
}

public void setQuestPersionId(Contractperson questPersionId) {
this.questPersionId = questPersionId;
}

public Adress getContractAdress() {
return this.contract_address_id;
}

public void setContractAdress(Adress contractAdress) {
contract_address_id = contractAdress;
}
public Timestamp getCreatedDate() {
return createdDate;
}

public void setCreatedDate(Timestamp createdDate) {
this.createdDate = createdDate;
}

}

Contractperson Entity:

package fi.passiba.contractdb.persistence;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;

@Entity

@NamedQueries( {
@NamedQuery(name = “Contractperson.findContractPersonByCompany”, query = “SELECT p FROM Contractperson AS p JOIN p.companyId AS c WHERE c.name = ?1″)
}
)
public class Contractperson implements Serializable {
@Id
@Column(name=”contractperson_id”)
@GeneratedValue (strategy = GenerationType.SEQUENCE)
@SequenceGenerator(name=”USER_SEQUENCE_GENERATOR_CONTRACTPERSON”,sequenceName=”contractperson_seq”)

private int contractpersonId;

@Column(name=”email”)
private String email;

@Column(name=”lastname”)
private String lastname;

@Column(name=”firstname”)
private String firstname;

@Column(name=”pincode”)
private String pincode;

@OneToOne(cascade = CascadeType.ALL, fetch=FetchType.LAZY)
@JoinColumn(name = “company_id”, referencedColumnName = “Company_id”)
private Company companyId;

@OneToOne(cascade = CascadeType.ALL,fetch=FetchType.LAZY)
@JoinColumn(name = “person_address_id”, referencedColumnName = “Adress_id”)

//@Column(name=”person_address_id”)
private Adress personAddressId;

private static final long serialVersionUID = 1L;

public Contractperson() {
super();
}

public int getContractpersonId() {
return this.contractpersonId;
}

public String getEmail() {
return this.email;
}

public void setEmail(String email) {
this.email = email;
}

public String getLastname() {
return this.lastname;
}

public void setLastname(String lastname) {
this.lastname = lastname;
}

public String getFirstname() {
return this.firstname;
}

public void setFirstname(String firstname) {
this.firstname = firstname;
}

public String getPincode() {
return this.pincode;
}

public void setPincode(String pincode) {
this.pincode = pincode;
}

public Company getCompanyId() {
return this.companyId;
}

public void setCompanyId(Company companyId) {
this.companyId = companyId;
}

public Adress getPersonAddressId() {
return this.personAddressId;
}

public void setPersonAddressId(Adress personAddressId) {
this.personAddressId = personAddressId;
}

}

DAO Interface class:

package fi.passiba.contractdb.persistence.dao;

import fi.passiba.contractdb.persistence.Contract;
import fi.passiba.contractdb.persistence.Contractperson;

import java.util.Date;
import java.util.List;

public interface ContractEAO{

public Contract findByContacId(int contactId);

public List findByDocumentName1(String documentName);
public List findByDocumentName2(String documentName);

public List getContactByDate(Date currentDate);

public List getContactByStatus(String status);

public List getContactByHostName(String hostName);

public List getContactByQuestName(String questName);

public List getContactByCompanyName(String questName);

public Contract createContract(Contract contract);

public Contract updateContract(Contract contract);

public void deleteContract(Contract contract);
}

Spring DAO class using JpaTemplate to access EntityManager

package fi.passiba.contractdb.persistence.dao;

import fi.passiba.contractdb.persistence.Contract;
import fi.passiba.contractdb.persistence.Contractperson;
import org.springframework.orm.jpa.support.JpaDaoSupport;

import java.util.Date;
import java.util.List;

public class ContractSpringEAO extends JpaDaoSupport implements ContractEAO {

public Contract findByContacId(int contactId) {
return getJpaTemplate().find(Contract.class, contactId);
}

public List findByDocumentName1(String documentName) {

String sql=”Select c FROM Contract c WHERE c.document1Name LIKE ?1 order by c.contractId”;
return (List)getJpaTemplate().find(sql,documentName);
}

public List findByDocumentName2(String documentName) {
return (List)getJpaTemplate().find(”Select c FROM Contract c WHERE c.document2Name LIKE ?1 order by c.contractId”,documentName);
}

public List getContactByCompanyName(String companyName) {
return (List)getJpaTemplate().find(”SELECT p FROM Contractperson p JOIN p.companyId as c WHERE c.name = ?1″,companyName);
}

public List getContactByDate(Date currentDate) {
return (List)getJpaTemplate().find(”SELECT c FROM Contract c WHERE c.createdDate > ?1″,currentDate);
}

public List getContactByHostName(String hostName) {
return (List)getJpaTemplate().find(”SELECT c FROM Contract c JOIN c.hostPersionId AS p WHERE p.lastname = ?1″,hostName);
}

public List getContactByQuestName(String questName) {
return (List)getJpaTemplate().find(”SELECT c FROM Contract c JOIN c.questPersionId AS p WHERE p.lastname = ?1″,questName);
}

public List getContactByStatus(String status) {
return (List)getJpaTemplate().find(”SELECT c FROM Contract c WHERE c.status = ?1″,status);
}

public Contract createContract(Contract contract) {
getJpaTemplate().persist(contract);
return contract;
}

public void deleteContract(Contract contract) {
getJpaTemplate().remove(contract);

}

public Contract updateContract(Contract contract) {
getJpaTemplate().merge(contract);
return contract;
}

}

Persistance.xml

fi.passiba.contractdb.persistence.Adress
fi.passiba.contractdb.persistence.Contract
fi.passiba.contractdb.persistence.Company
fi.passiba.contractdb.persistence.Contractperson
Test class to test Spring DAO class

fi.passiba.contractdb.persistence.Adress
fi.passiba.contractdb.persistence.Contract
fi.passiba.contractdb.persistence.Company
fi.passiba.contractdb.persistence.Contractperson
Junit test class extending abtract org.springframework.test.jpa.AbstractJpaTests-class

package test.passiba.contractdb;

import java.sql.Timestamp;
import java.util.List;

import org.springframework.test.jpa.AbstractJpaTests;

import fi.passiba.contractdb.buslogic.ContractService;
import fi.passiba.contractdb.persistence.Adress;
import fi.passiba.contractdb.persistence.Company;
import fi.passiba.contractdb.persistence.Contract;
import fi.passiba.contractdb.persistence.Contractperson;
public class ContractdbBusinessServiceImplTest extends AbstractJpaTests {

private ContractService empBusiness;

private Timestamp findByDate=null;

private static int id= 0;

public void setContractService(ContractService empBusiness) {
this.empBusiness = empBusiness;
}
protected String[] getConfigLocations() {
return new String[] { “classpath:/test/passiba/contractdb/contract-test-service.xml” };
}
protected void onSetUpInTransaction() throws Exception {
Contract contract2= new Contract();

findByDate= new Timestamp(System.currentTimeMillis());

contract2.setCreatedDate(findByDate);

Adress company_address1= new Adress();
company_address1.setAddr1(”TestiBulevardi 1″);
company_address1.setAddr2(”PL 564″);
company_address1.setCity(”Helsinki”);
company_address1.setCountry(”Suomi”);
company_address1.setPhone(”0976443333″);
company_address1.setState(”Uusimaa”);
company_address1.setZip(”00100″);
company_address1.setStatus(”1″);

Company company1 = new Company();
company1.setAdress(company_address1);
company1.setName(”Passiba Oyj”);
Adress company_address2= new Adress();

company_address2.setAddr1(”Normandiankuja 1″);
company_address2.setAddr2(”PL 23423″);
company_address2.setCity(”Helsinki”);
company_address2.setCountry(”Suomi”);
company_address2.setPhone(”0923567567″);
company_address2.setState(”Uusimaa”);
company_address2.setZip(”00100″);
company_address1.setStatus(”1″);

Company company2= new Company();

company2.setAdress(company_address2);
company2.setName(”Empire Oyj”);

Contractperson person1= new Contractperson();
person1.setCompanyId(company1);
person1.setEmail(”salesman@passiba.fi”);
person1.setFirstname(”Frank”);
person1.setLastname(”Miller”);
person1.setPincode(”231284-007″);
Adress person_address1= new Adress();

person_address1.setAddr1(”Sales deadendalley 1″);
person_address1.setAddr2(”PL 23423″);
person_address1.setCity(”London”);
person_address1.setCountry(”Englanti”);
person_address1.setPhone(”0923423423″);
person_address1.setState(”London”);
person_address1.setZip(”009923″);
person_address1.setStatus(”1″);

person1.setPersonAddressId(person_address1);

Contractperson person2= new Contractperson();
person2.setCompanyId(company2);
person2.setEmail(”salesman@eniro.fi”);
person2.setFirstname(”Eve”);
person2.setLastname(”SaleAce”);
person2.setPincode(”110280-009″);
Adress person_address2= new Adress();
person_address2.setAddr1(”Roihuvuorentie 1″);
person_address2.setAddr2(”PL 223423″);
person_address2.setCity(”Helsinki”);
person_address2.setCountry(”Suomi”);
person_address2.setPhone(”023423423423″);
person_address2.setState(”Uusimaa”);
person_address2.setZip(”00199″);
person_address2.setStatus(”1″);
person2.setPersonAddressId(person_address2);

contract2.setDocument1Name(”sopumus.pdf”);
contract2.setDocument1Path(”c:/docut”);
contract2.setDocument2Name(”sopimusliite.txt”);
contract2.setDocument2Path(”c:/files”);
contract2.setHostPersionId(person1);
contract2.setQuestPersionId(person2);
contract2.setStatus(”1″);
Adress contract_address=new Adress();

contract_address.setAddr1(”So¶rnaistenkatu 1″);
contract_address.setAddr2(”PL 23423″);
contract_address.setCity(”Helsinki”);
contract_address.setCountry(”Suomi”);
contract_address.setPhone(”0982342323″);
contract_address.setState(”Uusimaa”);
contract_address.setZip(”00199″);
contract_address.setStatus(”1″);

contract2.setContractAdress( contract_address);
contract2=empBusiness.createContract(contract2);
id=contract2.getContractId();
}
protected void onTearDownInTransaction()
throws Exception
{
//empBusiness.deleteContract(empBusiness.findByContacId(id));
}

public void testFindByDocumentName1()
{
List result = empBusiness.findByDocumentName1(”sopumus.pdf”);
assertEquals(1, result.size());
Contract contract2= (Contract)result.get(0);
assertEquals(”sopumus.pdf”,contract2.getDocument1Name());
}
public void testFindByDocumentName2()
{
List result = empBusiness.findByDocumentName2(”sopimusliite.txt”);
assertEquals(1, result.size());
Contract contract2= (Contract)result.get(0);
assertEquals(”sopimusliite.txt”,contract2.getDocument2Name());
}

public void testGetContactByDate()
{
List result = empBusiness.getContactByDate(findByDate);
assertEquals(1, result.size());

Contract contract2= (Contract)result.get(0);

assertEquals(findByDate,contract2.getCreatedDate());

}
public void testGetContactByStatus()
{
List result = empBusiness.getContactByStatus(”1″);
assertEquals(1, result.size());
Contract contract2= (Contract)result.get(0);
assertEquals(”1″,contract2.getStatus());

}

public void testGetContactByHostName()
{
List result = empBusiness.getContactByHostName(”Miller”);
assertEquals(1, result.size());
Contract contract2= (Contract)result.get(0);
assertEquals(”Miller”,contract2.getHostPersionId().getLastname());

}

public void testGetContactByQuestName(){

List result = empBusiness.getContactByQuestName(”SaleAce”);
assertEquals(1, result.size());
Contract contract2= (Contract)result.get(0);
assertEquals(”SaleAce”,contract2.getQuestPersionId().getLastname());

}

public void testGetContactByHostCompanyName(){

List result = empBusiness.getContactByCompanyName(”Passiba Oyj”);
assertEquals(1, result.size());
Contractperson contract2= (Contractperson)result.get(0);
assertEquals(”Miller”,contract2.getLastname());

}
public void testGetContactByQuestCompanyName(){

List result = empBusiness.getContactByCompanyName(”Empire Oyj”);
assertEquals(1, result.size());
Contractperson contract2= (Contractperson)result.get(0);
assertEquals(”SaleAce”,contract2.getLastname());

}

public void testInsertContract()
{
Contract contract2= new Contract();
Adress company_address1= new Adress();
company_address1.setAddr1(”TestiBulevardi 1″);
company_address1.setAddr2(”PL 564″);
company_address1.setCity(”Helsinki”);
company_address1.setCountry(”Suomi”);
company_address1.setPhone(”0976443333″);
company_address1.setState(”Uusimaa”);
company_address1.setZip(”00100″);
company_address1.setStatus(”1″);

Company company1 = new Company();
company1.setAdress(company_address1);
company1.setName(”Passiba Oyj”);
Adress company_address2= new Adress();

company_address2.setAddr1(”Normandiankuja 1″);
company_address2.setAddr2(”PL 23423″);
company_address2.setCity(”Helsinki”);
company_address2.setCountry(”Suomi”);
company_address2.setPhone(”0923567567″);
company_address2.setState(”Uusimaa”);
company_address2.setZip(”00100″);
company_address1.setStatus(”1″);

Company company2= new Company();

company2.setAdress(company_address2);
company2.setName(”Empire Oyj”);

Contractperson person1= new Contractperson();
person1.setCompanyId(company1);
person1.setEmail(”salesman@passiba.fi”);
person1.setFirstname(”Frank”);
person1.setLastname(”Miller”);

Adress person_address1= new Adress();

person_address1.setAddr1(”Sales deadendalley 1″);
person_address1.setAddr2(”PL 23423″);
person_address1.setCity(”London”);
person_address1.setCountry(”Englanti”);
person_address1.setPhone(”0923423423″);
person_address1.setState(”London”);
person_address1.setZip(”009923″);
person_address1.setStatus(”1″);

person1.setPersonAddressId(person_address1);

Contractperson person2= new Contractperson();
person2.setCompanyId(company2);
person2.setEmail(”salesman@eniro.fi”);
person2.setFirstname(”Eve”);
person2.setLastname(”SaleAce”);

Adress person_address2= new Adress();
person_address2.setAddr1(”Roihuvuorentie 1″);
person_address2.setAddr2(”PL 223423″);
person_address2.setCity(”Helsinki”);
person_address2.setCountry(”Suomi”);
person_address2.setPhone(”023423423423″);
person_address2.setState(”Uusimaa”);
person_address2.setZip(”00199″);
person_address2.setStatus(”1″);
person2.setPersonAddressId(person_address2);

contract2.setDocument1Name(”sopumus.pdf”);
contract2.setDocument1Path(”c:/docut”);
contract2.setDocument2Name(”sopimusliite.txt”);
contract2.setDocument2Path(”c:/files”);
contract2.setHostPersionId(person1);
contract2.setQuestPersionId(person2);
contract2.setStatus(”1″);
Adress contract_address=new Adress();

contract_address.setAddr1(”Sornaistenkatu 1″);
contract_address.setAddr2(”PL 23423″);
contract_address.setCity(”Helsinki”);
contract_address.setCountry(”Suomi”);
contract_address.setPhone(”0982342323″);
contract_address.setState(”Uusimaa”);
contract_address.setZip(”00199″);
contract_address.setStatus(”1″);

contract2.setContractAdress( contract_address);
contract2=empBusiness.createContract( contract2);
id=contract2.getContractId();
assertEquals(contract2.getDocument2Name(),empBusiness.findByContacId(id).getDocument2Name());
}

public void testUpdateContract(){

Contract contract=empBusiness.findByContacId(id);
contract.setDocument2Name(”tehdyt_tyotunnit.xls”);
contract=empBusiness.updateContract( contract);
assertEquals(”tehdyt_tyotunnit.xls”,empBusiness.findByContacId(id).getDocument2Name());

}
public void testDeleteContract(){

empBusiness.deleteContract(empBusiness.findByContacId(id));
assertNull(empBusiness.findByContacId(id));

}

}

download the source code from my homepage

Be sure to download hibernate Entitymanager and Hibernte core distributions from hibernate download-site .

In addition, in order to create the database schema download Postgres database and Spring framework with dependencies.

Add comment August 30th, 2007

New release of MyEclipse 6.0 - support for JPA and Spring 2.0 Integration…JPA Streaming video tutorial

Hi,

I have been tackling with issues related to JPA and Spring Integration and luckily the tools provided by MyEclipse enable a good start for developing web applications using JPA (Java Persistance API)and Spring 2.0. The only minus side was in the tool support was the support for handling relationships between entities (one-to-one,one-to-many ,many-to-many). I basically needed to take care of configuring these generated annotations to the entities.Good tutorial to get the JPA relationships terms as part of your work toolkit vocabulary is to view introductive streaming video tutorial about using the Java Persistance API by Patrick Linskey(Bea) and Mike Keith (Oracle). Good sequel to the first streaming video session is also Enterprise Development with JPA. Topics covered in this session include Abstract Entities, Data Models and Entity Caching to name few.
The good news is also that the tools support for crating skeleton Spring DAO classes to access the JPA entities. Read the article about Java Developer journal - MyEclipse Enterprise Workbench 6.0 offers Spring 2.0 ,Java 6 and JPA Support

In, addition to that take a brief moment of your time to focus on the Tutorial Writing JPA Applications by Patrick Linskey.One of the consideration of how to access Entities in JPA was to either use EntityManager directly or to use JpaTemplates to do the job for you. The Streaming video tutorial Spring and JPA by Rod Johnson and Costin Leau highlight the best practices using JPA with Spring …how to test your JPA DAO layer using AbstractJPaTest class found in springmock.jar file.

Other useful source of information for me has been the Hibernate Entitymanager specific documentation…as I focus on Hibernate as EntityManager when using JPA. Other useful tutorials has been the IBM’s Developerworks series as the following Introduction to Spring 2 and JPA.

You just need to be registered user in order to access the above mentioned tutorial. But the effort is minimal for the reward of becoming acquainted with new terms behind JPA and Spring 2.0. In addition to Spring I’ll focus on the near future to the framework Seams in the form of recently published book by Michale Yuan - Seams next-gen Web framework.

Read also IBM’s Developerwork tutorial about the usage of seams part 1,

usage of seams part2

and

usage of seams part 3

Add comment August 29th, 2007

Java Persistance API….reap the benefits of using JEE 5 Blueprints- using single API for handling Database persistance chores

It has been a while since my last web blog entry to this site. It has been due to the summer outdoor activities as I have been going out fishing quite on a regular basis. Well it doesn’t mean that I haven’t payed any attention to the new ideas boiling under the Umbrella of Java and JEE technology filed. My latest focus of interest have been standardizes Java Persistance API and how it would help me to get Java Database specific issues done in more elegant and coherent way. It has been proven to be very useful….as I was not earlier so familiar with annotations …the book EJB 3 in Action written by Debu Panda published by Manning has proved to be a rock solid tested technology enabling the developer to benefit the usage of EJB 3 technology stack of API. One of these is Java Persistance API. In case you would like to read book reviews about this book take a look at Javalobbys bookreview.

In addition to these book reviews the book author Debu Panda has posted good Java Persistance API series in JDJ journal specificly highlighting the Integratrion of Spring and Java Persistance API- Spring and Java EE 5 (Part 1) Java Developers’s Journal.

and Spring and Java EE 5 (Part 2) Java Developers’s Journal.

Also get acquainted with Java persistance API explained sample chapter. Also take a look at Oracles post by Debu Panda of Integrating Spring with Java Persistance API in coherent way - Using EJB 3.0 and Java Persistance API with Spring in OC4J.
Altghought the article is about Integration with Oracle OC4J JEE Container the book author has provided also sample code to play with other popular JEE Servers...including Jboss.

To see the online tutorial about the Java JPA(Java Persistance API) Blueprints ….take a look at the JavaPolis steamed video about the topic - Java EE 5 Blueprints (JPA) by Brian Leonard. The JEE 5 blueprints can be downloaded at the site jdev-site
In order to start experimenting with the JPA - download the latest eclipse JEE IDE and start experimenting with JPA projects.

I know there are some fanatic coders who prefer only to stick to open source technologies and not to pay attention to what is happening in JEE technology field. I personally feel that both of these segments Open source projects (Spring and Hibernate to name the popular ones) and JEE have lot to benefit from each other. So I wouldn’t rule out either of these technologies out just to stick with one specific way of implementing working solution.

1 comment July 29th, 2007

configuration issues of Myql server,Tomcat and reading application specific properties configuration file

Hi,

This month has been turning point to something new …with the learning curve of using hibernate combined with spring framework and also wicket as front end mvc framework. At first I faced a task of repackaging the given wicket+Spring+hibernate based application web archive file to be run on top of Apache Tomcat.

Tomcat specific how-to-listing provides good ways how to configure Tomcat to meet your specific needs.

First phase was to remove any Jetty specific jar files and other Servlet-api specific jar-files in given ant-build file. The ant specific section exclude is written false way ekslude in order to be displayed on this blog. The exclude word would leave it hidden.

webxml=”${src.web.dir}/WEB-INF/web.xml”
ekslude=”**/package.html”>

<ekslude name=”org.mortbay.*” />
<
ekslude name=”jasper*.jar” />


<
ekslude name=”hibernate/antlr-2.7.6.jar”/>
<
ekslude name=”hibernate/asm-attrs.jar” />
<
ekslude name=”hibernate/c3p0-0.9.1.jar”/>

<ekslude name=”hibernate/ehcache-1.2.3.jar” />
<
ekslude name=”hibernate/hibernate3.jar” />
<
ekslude name=”hibernate/jaxen-1.1-beta-7.jar” />
<
ekslude name=”hibernate/jdbc2_0-stdext.jar” />
<
ekslude name=”hibernate/jta.jar” />
<
ekslude name=”hibernate-annotations/ejb3-persistence.jar” />
<
ekslude name=”hibernate-annotations/hibernate-annotations.jar” />
<
ekslude name=”hibernate-annotations/hibernate-commons-annotations.jar” />

After this was done it was time to tackle with issue of not finding hibernate annotation specific jar-file and hibernate specific jar files….they were located in lib\hibernate-annotations and lib\hibernate and subdirectories. This resulted the Spring Bean instanziation Exception
Instantiation of bean failed; nested exception is

org.springframework.beans.BeanInstantiationException: Could not
instantiate bean class
[org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]:
Constructor threw exception; nested exception is
java.lang.NoClassDefFoundError:
org/hibernate/cfg/AnnotationConfiguration
Caused by: org.springframework.beans.BeanInstantiationException: Could
not instantiate bean class
[org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]:
Constructor threw exception; nested exception is
java.lang.NoClassDefFoundError:
org/hibernate/cfg/AnnotationConfiguration
Caused by: java.lang.NoClassDefFoundError:
org/hibernate/cfg/AnnotationConfiguration
at org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean.(AnnotationSessionFactoryBean.java:65)

The specific jar-files needed to be included under /web-inf/lib directory by using lib specific ant task.

This resolved the packinging problem. The installation of MySQL server was highlighted in Red Hat Enterprise Linux specific installation instructions. Also some ports were necessary to open when using iptables…the Iptables tutorial gives good ways how to specify which port should be opened. The reading of application specific configuration file was done using instrouction posted on Sun’s java forum

Add comment June 26th, 2007

Wiket for wicked people

Hi,

The beginning of this month has been a fresh breeze of learning new frameworks and the latest new comer has been the pure 100 % framework Wikect . 

The good way to get the grasp of how it functions is to learn it by taking a closer look at the examples provided with the wicket samples site. A good article about the detailed inner workings of this framework is revealed in article Wicket: A little Bit About Wicket by R.J. Lorimer. Other useful source of information is available in the form of tutorial - newuserguide.

The first impression of this framework is productivity…and impressive amount of samples give overview of the cababilities of this frameworks..allthought I wasn’t impressed by it way to provide customized way of handling errors in the web applications. The way around this problem was first to overwrite the onRuntimeException method of  IRequestCycleFactory http://www.mail-archive.com/wicket-user@lists.sourceforge.net/msg19389.html.
@Override
public wicket.Page onRuntimeException(wicket.Page page,
RuntimeException e)
{
System.out.println(”Page : ” + page);
return new ErrorPage(e);
}

A good way to disable wicket error page was explained in web blog entry  RuntimeException not being caught despite configuration by Igor VagnBer… other useful way of implementing user guides for the application is to include static html-pages by including them in wicket template html-files with wicket.markup.html.include tag - just as depicted in the sample

Add comment June 15th, 2007

Previous Posts