«前の日記(2007-12-24) 最新 次の日記(2007-12-26)» 編集

ToDo:

  • 99 深呼吸して、おちけつ (~12/31 あと252日)
  • 98 毎日アウトプットを重きにおいた目標をたてる (~12/31 あと252日)
  • 97 買物は行動を変えるもの・ことに限る (~12/31 あと252日)
  • 96 合理的な行動はときに我慢を強いる(~12/31 あと252日)

ɥozɐʞıɥ


2007-12-25 χmas [長年日記]

_ プレゼント

ひかぞーは大喜びだったらしい。何時までもピュアなココロを持っていて欲しいな。

_ [ORM] Hibernate3 Annotation

ちょっと色々調べた結果をまとめ始めます。 まずはいっとー簡単なシンプルなテーブルへのエントリー
CREATE TABLE `test`.`Employee` (
  `ID` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  `FistName` VARCHAR(45) NOT NULL,
  `LastName` VARCHAR(45) NOT NULL,
  PRIMARY KEY (`ID`)
)
ENGINE = InnoDB;
Hibernate AnnotationのModel
package org.hikazoh;
 
import java.io.Serializable;
import javax.persistence.*;
 
@Entity
@Table(name="Employee")
public class Employee implements Serializable {
	@Id
	@Column(name="ID")
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer iD;
	@Column(name="FirstName")
	private String firstName;
	@Column(name="LastName")
	private String lastName;
	public Integer getID() {
		return iD;
	}
	public void setID(Integer 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;
	}
}
 
サンプルコードは…
package org.hikazoh;
 
import org.hibernate.*;
import org.hibernate.cfg.AnnotationConfiguration;
 
public class SimpleTest {
 
	public static void main(String[] args) {
		SessionFactory sessionFactory =
			new AnnotationConfiguration()
			.addPackage("org.hikazoh")
			.addAnnotatedClass(Employee.class)
			.buildSessionFactory();
		Session session = sessionFactory.openSession();
		Transaction tx = null;
		try{
			tx = session.beginTransaction();
			Employee emp = new Employee();
			emp.setFirstName("Hika");
			emp.setLastName("Zou");
			session.save(emp);
			tx.commit();
		}catch(Exception e){
			if ( tx != null ){
				tx.rollback();
			}
		}finally{
			session.close();
		}
		sessionFactory.close();
	}
 
}
 


2002|09|10|11|12|
2003|01|02|03|04|05|06|07|08|09|10|11|12|
2004|01|02|03|04|05|06|07|08|09|10|11|12|
2005|01|02|03|04|05|06|07|08|09|10|11|12|
2006|01|02|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|
«前の日記(2007-12-24) 最新 次の日記(2007-12-26)» 編集