当我使用GenerationType.IDENTITY或GenerationType.AUTO为我的表ID,我坚持一个事务内的实体,数据瞬间插入,并在事务结束之前! !JPA 2 /休眠/ MySql GenerationType.AUTO
我试图改变whit GenerationType.TABLE,生成并执行我的MYSQL数据库中的新关联的DDL,现在它正在工作。 有人可以解释我为什么吗?
提取物:
@Table
@Entity
public class Foo implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", nullable = false, unique = true)
private Long id;
...
}
@Repository
public class EntityDaoServiceImpl {
@PersistenceContext
protected EntityManager em;
@Transactional
public void testFooCreation() {
Foo foo = new Foo();
em.persit(foo);
//at this point with the AUTO or IDENTITY strategie,
//i ve got an effective insert in base otherwise with the TABLE strategie,
//the insert is effective at the end of my transaction (the excepted behavior)
}
}
'我有一个有效的插入基地'你如何检查? (在'em.persist();'后面添加一个伪'System.out.println(“Breakpoint”);'在那里放置一个断点,并用外部工具查看你的表Foo,看看新行是) – ben75