작성
·
228
0
package hellojpa;
import javax.persistence.*;
public class JpaMain {
public static void main(String[] args) {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("hello");
EntityManager em =emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();
try {
// Member member1 = new Member();
// member1.setName("gggg");
// Member member2 = new Member();
// member1.setName("gggg2");
// em.persist(member1);
// em.persist(member2); <-이렇게 하면
//Hibernate:
// call next value for hibernate_sequence
//Hibernate:
// call next value for hibernate_sequence 이렇게 나오고 insert문이 안나오고
// 데이타베이스에 커밋이 안되구요
Member member1 = new Member();
member1.setName("gggg");
Member member2 = new Member();
em.persist(member1); //<-이렇게 하면 insert문도 정상적으로 나오는데 차이점을 모르겠어요 ㅠㅠ
tx.commit();
}catch (Exception e) {
tx.rollback();
}finally {
em.close();;
}
emf.close();
}
}
package hellojpa;
import javax.persistence.*;
import java.util.Date;
@Entity
public class Member {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
private Long id;
@Column(name = "NAME",nullable = false,length = 10)
private String name;
private Integer age;
@Enumerated(EnumType.STRING)
private RoleType roleType;
@Temporal(TemporalType.TIMESTAMP)
private Date createdDate;
@Temporal(TemporalType.TIMESTAMP)
private Date lastModifedDate;
@Lob
private String description;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public RoleType getRoleType() {
return roleType;
}
public void setRoleType(RoleType roleType) {
this.roleType = roleType;
}
public Date getCreatedDate() {
return createdDate;
}
public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}
public Date getLastModifedDate() {
return lastModifedDate;
}
public void setLastModifedDate(Date lastModifedDate) {
this.lastModifedDate = lastModifedDate;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}