annotation time type

package ctl.annotion.teacher;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;//注意是javax.persistence
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@Entity
@Table(name="TTeacher")//javax.persistence.Table;类Teacher映射表TTeacher在xml中用table="TTeacher"来表示
public class Teacher {
private int id;
private String name;
private String title;

private Date datet;//You cannot use date as a field in orcale

//Use type="" in xml to set the field type

//In mysql, it can be incremented from 1, but in orcale, it is not from the beginning, but from the current id value in the current database.
@Id
@GeneratedValue(strategy = GenerationType.AUTO )
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Column
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}


@Column
@Temporal(TemporalType.DATE)// in mysql 2013-01-18 in orcale 2013-01-18 00:00:00
// @Temporal(TemporalType.TIME)// in mysql at 12:40:54 2013-01-18 13:05:00
in orcale //@Temporal(TemporalType.TIMESTAMP)// 2013-01-18 12:42:24 in mysql 2013-01-18 13:07:28:328000 in orcale
public Date getDatet() {
return datet;
}
public void setDatet(Date datet) {
this.datet = datet;
}


}




package junit.test.teacher;
import java.util.Date;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import ctl.annotion.teacher.Teacher;
public class TeacherTest { private static SessionFactory sf=null;@BeforeClasspublic static void beforeClass(){ //sf=new AnnotationConfiguration().configure("Orcalehibernate.cfg.xml").buildSessionFactory();sf=new AnnotationConfiguration().configure("hibernate.cfg.xml").buildSessionFactory();





}
@Test
public void testTeacherSave() { Teacher t = new Teacher();t.setName("zxp");t.setTitle("Ich liebe dich");t.setDate(new Date());Session session = sf.openSession();session.beginTransaction();session.save(t);session.getTransaction().commit();}@Testpublic void print(){ System.out.println(new Date());}@AfterClasspublic static void afterClass(){ sf.close();} }




















Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324134612&siteId=291194637